BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi ,

Any one can help me to resolve this issue. i want to create new variables for same value in A variable.

DATA SMP;
INPUT A B C;
DATALINES;
1 20 30
1 32 40
1 45 60
2 28 40
2 30 40
;
i have tried in the following way but i dint get the result dataset
DATA SMP1;
ARRAY S(3) A1 A2 A3;
ARRAY SB(3) B1 B2 B3;
ARRAY SC(3) C1 C2 C3;
SET SMP;
BY A;
IF FIRST.A THEN DO I=1 TO 3;
S(I)=A;
SB(I)=B;
SC(I)=C;
END;
RUN;

out put is:

OUTPUT;
A B C A1 B1 C1 A2 B2 C2
1 20 30 1 32 40 1 45 60
2 28 40 2 30 40 . . .


Thanks in advance for response


Thanks
Slone
4 REPLIES 4
LinusH
Tourmaline | Level 20
This seems like a transpose to me.
Have a look at PROC TRANSPOSE.
If you want to do it in a data step, you might want to use RETAIN and explicit OUTPUT techniques instead.

/Linus
Data never sleeps
deleted_user
Not applicable
Hi Linus,

Thank's for response,
i can create this by using Transpose and then merge these individual datasets , but is there any possibility, like hold that paritcular observation and check across the same group observations in a single data step.
LinusH
Tourmaline | Level 20
I am absolutely no array king, but here's a suggestion. I didn't bother to include A1-A3, since I couldn't understand what use you have for them, since A is the key...?

DATA SMP1;
SET SMP;
array bb(3) b1-b3;
array cc(3) c1-c3;
retain b1 b2 b3 c1 c2 c3 n;
BY A;
if first.a then do;
n = 1;
do i=1 to dim(bb);
bb(i) = .;
cc(i) = .;
end;
end;
bb(n) = b;
cc(n) = c;
put _all_;
IF LAST.A THEN output;
n+1;
RUN;
Data never sleeps
deleted_user
Not applicable
Hi Linus,


Thank u very much, This is what i am looking for.




Thanks
Slone

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 4 replies
  • 709 views
  • 0 likes
  • 2 in conversation