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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.