Hi,
I currently have a macro set up that 'profiles' my customers - %Profile(&Group)
The macro runs through several datastep procedures and essentially creates a standard output data set named Profile_&Group.
If I have 3 profiles to create I would run the macro 3 times for example:
%Profile(HighValue) ; (output: Profile_HighValue)
%Profile(MedValue) ; (output: Profile_MedValue)
%Profile(LowValue) ; (output: Profile_LowValue)
After the macro is complete I have a separate code I would run manually to merge the output datasets into a summary table:
Data Profile_Summary ; Merge Profile_HighValue Profile_MedValue Profile_LowValue ;
by ID;
run ;
Sometimes I would only have 2 groups (High,Med) or possibly 5+ groups to profile and merge to one single dataset.
My question:
What is the best way to incorporate my datastep to merge the profile tables together within the macro?
Thanks for your help.
KD
You could write a new macro that would control all the processing. One example:
%macro control (mylist);
%local i next_name;
%do i=1 %to %sysfunc(countw(&mylist));
%let next_name = %scan(&mylist, &i);
%profile (&next_name)
%end;
data profile_summary;
merge %do i=1 %to %sysfunc(countw(&mylist));
%let next_name = %scan(&my_list, &i);
profile_&next_name
%end;
;
by ID;
run;
%mend control;
%control (HighValue LowValue MedValue)
This is untested code, so you may find a tweak is in order. But it sounds like the program form is exactly what you are asking for. Good luck.
You could write a new macro that would control all the processing. One example:
%macro control (mylist);
%local i next_name;
%do i=1 %to %sysfunc(countw(&mylist));
%let next_name = %scan(&mylist, &i);
%profile (&next_name)
%end;
data profile_summary;
merge %do i=1 %to %sysfunc(countw(&mylist));
%let next_name = %scan(&my_list, &i);
profile_&next_name
%end;
;
by ID;
run;
%mend control;
%control (HighValue LowValue MedValue)
This is untested code, so you may find a tweak is in order. But it sounds like the program form is exactly what you are asking for. Good luck.
Thank you Astounding, this worked perfectly (just had one typo in above code).
can you use?
data Summary;
merge profile_:;
by ID;
run;
Great idea if it works, you could also do:
data _null_;
set sashelp.vtables (where=(libname="WORK" and index(MEMNAME,"PROFILE")>0);
by libname;
if first.libname then call execute('data profile_summary; merge ');
call execute(" "||strip(memname));
if last.libname then call execute('; by id; run;');
run;
RW9 wrote:
Great idea if it works, you could also do:
I use it all the time.:smileyshocked:
How did you make that work?? I don't think SAS recognizes the the colon for datasets.
23 data class_1 class_2 Class_3;
24 set sashelp.class;
25 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS_1 has 19 observations and 5 variables.
NOTE: The data set WORK.CLASS_2 has 19 observations and 5 variables.
NOTE: The data set WORK.CLASS_3 has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.02 seconds
26 data class;
27 merge class_:;
28 by name;
29 run;
NOTE: There were 19 observations read from the data set WORK.CLASS_1.
NOTE: There were 19 observations read from the data set WORK.CLASS_2.
NOTE: There were 19 observations read from the data set WORK.CLASS_3.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.