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.
The new date variavle doesn't have a format. Just give it a date format with the statement
format date yymmdd10.;
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.
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.)
The new date variavle doesn't have a format. Just give it a date format with the statement
format date yymmdd10.;
Thanks.
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.
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.