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;
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.