DATA Step, Macro, Functions and more

Create a dataset splitting the column of another dataset.

Reply
N/A
Posts: 0

Create a dataset splitting the column of another dataset.

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
N/A
Posts: 0

Re: Create a dataset splitting the column of another dataset.

Posted in reply to deleted_user
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.
N/A
Posts: 0

Re: Create a dataset splitting the column of another dataset.

Posted in reply to deleted_user
Perfect!
Thank you!!!
Ask a Question
Discussion stats
  • 2 replies
  • 127 views
  • 0 likes
  • 1 in conversation