Help using Base SAS procedures

how to separate a record into multiple rows

Reply
Occasional Contributor
Posts: 17

how to separate a record into multiple rows

Here is what the dataset looks like this right now

NAMEA1A2A3P1P2P3
MIKE1.21.681.62.96.73.0
NANCY2.36.31.97.63.67.1
JEN2.12.22.46.27.13.4

I want the output to look like this

NAMEA1A2A3P1P2P3
MIKE1.21.681.6...
MIKE...2.96.73.0
NANCY2.36.31.9...
NANCY...7.63.67.1
JEN2.12.22.4...
JEN...6.27.13.4

Can someone please help on how to code in SAS Enterprise Guide? Any hint is helpful.

Respected Advisor
Posts: 3,124

Re: how to separate a record into multiple rows

data want;

set have have;

call missing(of pSmiley Happy;

output;

set have;

call missing(of aSmiley Happy;

output;

run;

Contributor
Posts: 23

Re: how to separate a record into multiple rows

You can split the data set into two subset and then combine them.

Here is coding:

data a (keep= name a1-a3) p (keep=name p1-p3);

set old;

run;

data want;

set a p;

run;

proc sort data=want;

by name;

run;

Respected Advisor
Posts: 4,787

Re: how to separate a record into multiple rows

Another variation on the theme keeps the names in their original order:

data  just_p ;

   set have;

   call missing(of aSmiley Happy;

run;

data want;

set have;

call missing(of pSmiley Happy;

output;

set just_p;

output;

run;

Grand Advisor
Posts: 9,466

Re: how to separate a record into multiple rows

Code: Program

data have;
infile cards expandtabs truncover;
input name $ a1-a3 p1-p3;
cards;
MIKE 1.2 1.68 1.6 2.9 6.7 3.0
NANCY 2.3 6.3 1.9 7.6 3.6 7.1
JEN 2.1 2.2 2.4 6.2 7.1 3.4
;
run;

data want;
set have;
array x{3} _temporary_;
array _p{*} p1-p3;
do i=1 to dim(x);
  x{i}=_p{i};
end;
call missing(of p:);output;
do i=1 to dim(x);
  _p{i}=x{i};
end;
call missing(of a:);output;
drop i;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 451 views
  • 2 likes
  • 5 in conversation