# limit data in gplot with macro array

#### kriscrowe

##### New Member
I have a horizontal dataset containing quarterly chargeoff data for various products. Within the dataset variables names are product specific(productA_bal, productA_chgoff, productA_net_chgoff, productB_bal, productB_chgoff, productB_net_chgoff, and so on). I have created a macro array that reads in the product variables(dependent variables) as well as the remaining variables which are the independent variables and subsequently plots each permutation of dependent variable vs. independent variable. See below.

proc gplot data=all;

%do i=1 %to &NUMDEP;
%do j=1 %to &NUMIND;

plot &&DEP&i * &&IND&j; run;

%end;
%end;

The data however is not balanced, so the resulting plots include quarters that do not apply for some products. I would like to selectively adjust the starting quarter or row for each product such that productA variables are plotted against independent variables for 2004Q1 forward and productB variables are plotted for period 2010Q3 forward, for example. Any ideas?

#### Jrb599

##### New Member
Okay this should get you you started. I hate writing code without a dataset to test against, and quite frankly - I'm too lazy right now to generate a fake one...give this a try and let me know if it returns any errors

Code:
 /*Plot B Products*/
PROC GPLOT data=ALL;
%do i=1 %to &NUMDEP;
%IF %index(%scan(%lowcase(&numdep),&i),producta_)>0%then %do;
%do j=1 %to &NUMIND;
plot &&DEP&i * &&IND&j;
%end;
%end;
%end;
where date >='01JAN2004'd;
RUN;
QUIT;

/*Plot B Products*/
PROC GPLOT data=ALL;
%do i=1 %to &NUMDEP;
%IF %index(%scan(%lowcase(&numdep),&i),productb_)>0 %then %do;
%do j=1 %to &NUMIND;
plot &&DEP&i * &&IND&j;
%end;
%end;
%end;
where date >='01JUL2010'd;
RUN;
QUIT;
Oh and I just guessed on the dates for Q1/Q3 - just made them up

Last edited:

#### kriscrowe

##### New Member
Thank you JRB. I appreciate the help. Yes that works and is similar to what I have in the complete code below.

The thing that's hanging me up is there are 37 "products" (dependent variables) for which the starting date needs to be specified. Is there a way around replicating the gplot for each product?

%macro allvars;

proc sql noprint;
select count(*) into :numind from allvars
where substr(name,1,3) in ('BON','CPI','CRE','FMA','GDP','HPI','INC','SP5','TBI','UNE') ;
select name into :ind1-:ind%left(&NUMIND) from allvars
where substr(name,1,3) in ('BON','CPI','CRE','FMA','GDP','HPI','INC','SP5','TBI','UNE') ;
select count(*) into :numdep from allvars
where substr(left(reverse(name)),1,4) in ('etar');
select name into :dep1-:dep%left(&NUMDEP) from allvars
where substr(left(reverse(name)),1,4) in ('etar');
quit;

proc gplot data=all;

%do i=1 %to &NUMDEP;
%do j=1 %to &NUMIND;

plot &&DEP&i * &&IND&j; run;

%end;
%end;

quit;

%mend;

%allvars;

#### Jrb599

##### New Member
Please reread my post - I've edited it so many times to fix errors and make it better that hopefully I addressed what you needed.

GPLOT is an old product and someways only around to help legacy systems. There might be a way, but I'm not sure. What's wrong with running gplot several times? Also my code writes GPLOT twice, not 37 times. Of course I'm also assuming we're only worrying about the two dates you listed above.

Edit: Maybe there is a nifty way you can transform your dataset so it reflects via by groups instead and use a by statement in PROC GPLOT? Otherwise you'll probably need to run gplot for each set of dates. You could probably set this up in a table and then load it into macros.

Last edited: