DATA Step, Macro, Functions and more

creating data set

Reply
N/A
Posts: 0

creating data set

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
Super User
Posts: 5,260

Re: creating data set

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

Re: creating data set

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.
Super User
Posts: 5,260

Re: creating data set

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

Re: creating data set

Hi Linus,


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




Thanks
Slone
Ask a Question
Discussion stats
  • 4 replies
  • 117 views
  • 0 likes
  • 2 in conversation