Hi all,
I have about 48 data sets named
pfreq_and_pl_g1_gr1
pfreq_and_pl_g1_gr2
pfreq_and_pl_g1_gr3
pfreq_and_pl_g1_gr4
pfreq_and_pl_g2_gr1
pfreq_and_pl_g2_gr2
...
"g" goes up to 12.
and "gr" goes up to 4.
I want to merge them based on the "g". For example one merged data set will include (pfreq_and_pl_g1_gr1, pfreq_and_pl_g1_gr2, pfreq_and_pl_g1_gr3, pfreq_and_pl_g1_gr4), the other data set will include (pfreq_and_pl_g2_gr1, pfreq_and_pl_g2_gr2, pfreq_and_pl_g2_gr3, pfreq_and_pl_g2_gr4).
Merging will be based on the data set's name, not a variable. How can I do that?
Thank you
If those datasets share the same structure, you probably want to.stack them, not merge.
Try this:
%macro dsnames;
%do i = 1 %to 12;
%do j = 1 %to 4;
npfreq_and_pl_g&i._gr&j.
%end;
%end;
%mend;
data final_grade;
set
%dsnames
indsname=dsname
;
group = input(scan(dsname,-1,'r'));
run;
not tested, posted from my tablet.
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.