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.
| ID | January | February | March |
| 1 | 1 | 1 | 4 |
| 2 | 14 | 12 | 33 |
| I3 | 5 | 3 | 3 |
| 4 | 1 | 3 | 3 |
Any help is much appreciated
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;
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;
Thank you!
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;
thank you. this is what I want, cheers!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.