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.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 785 views
  • 0 likes
  • 3 in conversation