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
Super User

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
Super User

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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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