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

Hi guys, 

suppose to do a proc summary and you have a list of variables ending with "_0" you want to give to var. How can you indicate all that variables at once? They are not in a specified order to use "fromthefirst--tothelast".

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

There is no short way of specifying variables with a common suffix. 

 

Do something like this, put them in a macro vairable and use that in your Proc Summary

 

data have;
input ID One_0 SecondVar Two_0 One Three_0 Three;
datalines;
1 1 2 3 1 2 3
2 4 5 6 4 5 6
3 7 8 9 7 8 9
4 1 2 3 1 2 3
5 4 5 6 4 5 6
;

%let suffix=_0;
 
proc sql noprint;
   select name into :vars separated by ' ' 
   from dictionary.columns 
   where upcase(libname)=upcase('work') 
     and upcase(memname)=upcase('have')
     and upcase(substr(name,length(name)-(length("&suffix")-1),length("&suffix")))=upcase("&suffix");
quit;
 
%put &vars;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

There is no short way of specifying variables with a common suffix. 

 

Do something like this, put them in a macro vairable and use that in your Proc Summary

 

data have;
input ID One_0 SecondVar Two_0 One Three_0 Three;
datalines;
1 1 2 3 1 2 3
2 4 5 6 4 5 6
3 7 8 9 7 8 9
4 1 2 3 1 2 3
5 4 5 6 4 5 6
;

%let suffix=_0;
 
proc sql noprint;
   select name into :vars separated by ' ' 
   from dictionary.columns 
   where upcase(libname)=upcase('work') 
     and upcase(memname)=upcase('have')
     and upcase(substr(name,length(name)-(length("&suffix")-1),length("&suffix")))=upcase("&suffix");
quit;
 
%put &vars;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 248 views
  • 1 like
  • 2 in conversation