BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
m1986MM
Obsidian | Level 7

Hi everyone,

I have a wide dataset similar to following table and want to reshape it to long. Variables' formats: name (character), date(date), new_id and original_id(numeric)

name

Date1

New_id1

Cert_id1

Date2

New_id2

Cert_id2

The columns continue to 5.

 

I used the following code, however it doesn't work and I think the reason is the different formats I have. 

 

DATA long;

SET wide;

ARRAY adate(1:5) date1 - date5 ;

ARRAY anew_id(1:5) new_id1 - new_id5;

ARRAY aoriginal_id(1:5) original_id1 - original_id5;

DO change = 1 to 5 ;

date = adate(change);

new_id =anew_id(change);

original_id =aoriginal_id(change);

OUTPUT;

END;

DROP date1 - date5 new_id1 - new_id5 original_id1 - original_id5;

RUN;

 

I appreciate any and all suggestions.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The new date variavle doesn't have a format. Just give it a date format with the statement

 

format date yymmdd10.;

PG

View solution in original post

4 REPLIES 4
Reeza
Super User

Your code appears correct to the naked eye, and your methodology is correct.

 

As long as type are the same for the same variable groups that shouldn't be an issue either.  

Please post your log and explain how it's not working. 

m1986MM
Obsidian | Level 7

The log window looks fine.

 

NOTE: There were 263872 observations read from the data setWORK.WIDE.

NOTE: The data set WORK.LONG has 1319360 observations and 5 variables.

NOTE: DATA statement used (Total process time): real time 0.11 seconds cpu time 0.10 seconds

 

However in the newe table values are not correct. For example, the new date variable does not contain date values anymore. It's not even date format, YYMMDD10.

 

In the following link, example 5, explains the reshaping with a string variable.

 

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

 

Because of this I assumed that format of the date vriable is problematic. However, I don't know why it should be the case when the type of variable (date) is numeric. (its format is YYMMDD10.)

 

 

PGStats
Opal | Level 21

The new date variavle doesn't have a format. Just give it a date format with the statement

 

format date yymmdd10.;

PG
m1986MM
Obsidian | Level 7

Thanks.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3300 views
  • 2 likes
  • 3 in conversation