BookmarkSubscribeRSS Feed
SAShole
Pyrite | Level 9

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.

4 REPLIES 4
FriedEgg
SAS Employee

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;

Linlin
Lapis Lazuli | Level 10

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;

SAShole
Pyrite | Level 9

Thanks FriedEgg & LinLin.

@LinLin I never knew that you could put a do loop in a keep statement!

Haikuo
Onyx | Level 15

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1770 views
  • 6 likes
  • 4 in conversation