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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 2384 views
  • 6 likes
  • 4 in conversation