BookmarkSubscribeRSS Feed
肉肉
Calcite | Level 5

Hello,

 

I have 150 Obs with mutiple statment from 24 months, so its a long list, and I am trying to make it Long to wide.

 

here I have my code, can you please have a look, so see how would I add a Do-Loop on this to make my life easier? Thank you.

 

data Test;

set From;

by ID;

 

retain Statement1-Statement24;

 

array misser Statement1-Statement24;

 

if first.ID=1 then do over misser;

misser =.;

end;

 

if Count=1 then do;

Statement_01=Statement;

end;

if CountForSTMT=2 then do;

Statement_02=Statement;

end;

.

.

.

if CountForSTMT=24 then do;

Statement_24=Statement;

end;

 

if last.ID=1 then output;

 

run;

 

2 REPLIES 2
Reeza
Super User

Is this what you're trying to do:

http://www.ats.ucla.edu/stat/sas/modules/widetolong_data.htm

 

If so, consider using a direct PROC TRANSPOSE instead, see the examples here:

http://www.ats.ucla.edu/stat/sas/modules/wtol_transpose.htm

ballardw
Super User

First clarify if you want Statement_02 as used in your assignment or Statement2 as used in your Retain and Array statements.

You don't help yourself by having two different indexing variables count and CountForStmt.

No need for any do loop since your CountForStmt is the index into the array that you need:

 

if CountForStmt> 1 then misser[CountForStmt]=statement;

replace all of the 2 through 24 code that you indicate.

 

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 choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1383 views
  • 0 likes
  • 3 in conversation