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

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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 390 views
  • 1 like
  • 2 in conversation