BookmarkSubscribeRSS Feed
HitmonTran
Pyrite | Level 9

Hi

 

I want to pull all distinct values from variable "SITEID" and then using them in a macro without typing all 118 SITEID values into  a proc step below:

 

proc sort data=x;
by subject;
where siteid= "&siteid";
run;
2 REPLIES 2
ballardw
Super User

Did you READ the response in https://communities.sas.com/t5/SAS-Programming/how-to-NOT-manually-type-all-50-values-in-a-macro/m-p...

 

I show you exactly how to do that

proc sql noprint;
   select distinct origin into :originlist separated by ' '
   from sashelp.cars
   ;
quit;

for one.

 

and how to use the list.

In a couple of different places.

 

 

andreas_lds
Jade | Level 19

Storing data in macro-variable is hardly necessary at all, so you may want to explain what you are trying to achieve. The step you showed needs at least a tweak setting the name of the dataset created according to the value of &siteId. But here the trouble starts: All values of SiteID must valid sas-names. So if you are not 100% sure that they won't invalidate the datasets name, you have to pre-process the values, taking care of not creating duplicates when replacing bad chars. This is much work. compared to by-group processing, which is available in nearly all procs.

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1897 views
  • 0 likes
  • 3 in conversation