BookmarkSubscribeRSS Feed
dustychair
Pyrite | Level 9

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

3 REPLIES 3
dustychair
Pyrite | Level 9
Thank you @Kurt_Bremser. I am sure there is an easier way to do that. Here is what I did. It worked but I still had to play a little bit in excel.


%macro combine(d);

%do i = 1 %to 12;
data npfreq_and_pl_g&i._gr1;
set npfreq_and_pl_g&i._gr1;
group=1;

data npfreq_and_pl_g&i._gr2;
set npfreq_and_pl_g&i._gr2;
group=2;

data npfreq_and_pl_g&i._gr3;
set npfreq_and_pl_g&i._gr3;
group=3;

data npfreq_and_pl_g&i._gr4;
set npfreq_and_pl_g&i._gr4;
group=4;
run;
data final_grade_&i.;
set npfreq_and_pl_g&i._gr1 npfreq_and_pl_g&i._gr2 npfreq_and_pl_g&i._gr3 npfreq_and_pl_g&i._gr4;
%end;
run;
%mend;
%combine ;
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 590 views
  • 0 likes
  • 2 in conversation