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

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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