This is what I have-- have.sas7bdat
I want to create a list of macro variables in a way that when I invoke
want_1_3 i get MDX
want_2_2 i get A4 3.0 4dr
How should I proceed?
proc sort data=sashelp.cars nodupkey out=cars(keep=make model);
by make model;
run;
data have;
set cars;
by make model;
retain id_groups 0;
if first.make then
do;
id_groups+1;
id_value_groups=1;
end;
else
do;
id_value_groups+1;
end;
run;
This?
data have; set cars; by make model; retain id_groups 0; if first.make then do; id_groups+1; id_value_groups=1; end; else do; id_value_groups+1; end; call symputx(catx('_','Make',id_groups,Id_value_groups),Model); run; %put &make_1_3; %put &make_2_2;
If the only purpose of the data step is to create the macro variables then use a DATA _NULL_ as you don't need the data set.
Where does SQL come into this? SQL doesn't use BY groups per se.
This?
data have; set cars; by make model; retain id_groups 0; if first.make then do; id_groups+1; id_value_groups=1; end; else do; id_value_groups+1; end; call symputx(catx('_','Make',id_groups,Id_value_groups),Model); run; %put &make_1_3; %put &make_2_2;
If the only purpose of the data step is to create the macro variables then use a DATA _NULL_ as you don't need the data set.
Where does SQL come into this? SQL doesn't use BY groups per se.
True. I dont know why I was thinking this can be done only by SQL. Thank You very much @ballardw
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.