BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
meckarthik
Quartz | Level 8

Hi,

creating some automation report, I need to select only the last 3 columns. for example: If I run in April need to select column Jan, Feb, Mar. If run in  Dec select Sep, Oct, Nov along with ID, etc.

IDJanuaryFebruaryMarch
1114
2141233
I3533
4133

 

Any help is much appreciated 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You can produce some macro variables .

 

%let one=%sysfunc(intnx(month,%sysfunc(today()),-1,s),monname.);
%let two=%sysfunc(intnx(month,%sysfunc(today()),-2,s),monname.);
%let three=%sysfunc(intnx(month,%sysfunc(today()),-3,s),monname.);


%put &one &two &three;

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

you could try the below example of sashelp.class where we are keeping only the last three apart from the main variable i..e name

 

proc sql;
select name into: vars separated by ' ' from dictionary.columns where libname='SASHELP' and memname='CLASS' having max(varnum)-varnum in (0,1,2);
quit;
%put &vars;

data want;
set sashelp.class;
keep name &vars;
run;
Thanks,
Jag
meckarthik
Quartz | Level 8

Thank you! 

Ksharp
Super User

You can produce some macro variables .

 

%let one=%sysfunc(intnx(month,%sysfunc(today()),-1,s),monname.);
%let two=%sysfunc(intnx(month,%sysfunc(today()),-2,s),monname.);
%let three=%sysfunc(intnx(month,%sysfunc(today()),-3,s),monname.);


%put &one &two &three;
meckarthik
Quartz | Level 8

thank you. this is what I want, cheers! 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1809 views
  • 4 likes
  • 3 in conversation