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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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