BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi all,
I’d like to create a dataset with two columns splitting the column of another dataset.
I have a dataset like this:

data A;
length report $15;
input report;
datalines;
Germany_1
Italy_1
Italy_2
Italy_3
Germany_2
Italy_4
Germany_3
Italy_5
Italy_6
;
run;

And I need to create a new dataset based in the other one. It should be like this:

Germany_1 Italy_1
Germany_1 Italy_2
Germany_1 Italy_3
Germany_2 Italy_4
Germany_3 Italy_5
Germany_3 Italy_6

I can use the condition that the variable begins with Germany or Italy, but I don’t know how.

Can anybody help me?

Thanks!
Elena
2 REPLIES 2
deleted_user
Not applicable
use following code:

data b;
set a;
retain temp;
if _n_ = 1 then temp = report;
if index(scan(temp,1,'_'),scan(report,1,'_')) then temp = report;
if temp = report then delete;
run;

GL.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1161 views
  • 0 likes
  • 1 in conversation