I have a dataset that looks like this:
CBG tru1-tru100.
where cbg is a unique identifier tru is an array with a label that identifies its monthly date.
i want to pull the data together into quarters, so i want every 3rd column for tru1-tru100.
Any Ideas?
i was thinking about transposing and then using the mod function.
data foo;
length cbg tru1-tru100 8;
run;
proc sql noprint;
select name into :names separated by ' '
from dictionary.columns
where libname='WORK'
and memname='FOO'
and substr(name,1,3)='tru'
and mod(input(substr(name,4),3.),3)=0;
quit;
data bar;
set foo;
keep &names;
run;
data have;
id =22;
array q(*) q1-q30;
do _n_=1 to dim(q);
q(_n_)=1; end;
run;
%macro test;
data want;
set have;
keep id %do i=3 %to 30 %by 3;
q&i %end;;
run;
%mend;
%test
proc contents data=want;run;
Thanks FriedEgg & LinLin.
@LinLin I never knew that you could put a do loop in a keep statement!
Hi Jeffrey,
What LinLin has used is not a regular 'do loop', instead, it was a Macro loop, which, for one, you can only use it inside a macro; for two, you can literally put it any where inside macro. Its purpose is nothing but to render a 'text string'.
Regards,
Haikuo
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.