- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
suppose to have the following:
data DB;
input ID :$20. Admission :date09. Discharge :date09. Class Value;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2 0.32
0001 21FEB2015 31DEC2015 2 0.32
0001 01MAR2018 30SEP2018 3 0.43
0001 01JAN2019 31DEC2019 3 0.43
0002 01JAN2015 31DEC2015 2 1.92
0002 01JAN2019 31OCT2019 2 1.92
0003 08FEB2014 10MAR2014 1 4.32
0003 16JUN2015 13JUL2015 1 4.32
0004 04MAY2016 10MAY2016 3 3.22
0004 13SEP2017 15NOV2017 3 3.22
0004 09DEC2018 31DEC2018 3 3.22
;
Is there a way to get the following?
data DB1;
input ID :$20. Admission :date09. Discharge :date09. Class Class1 Class2 Class3 Class4;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2 . 0.32 . .
0001 21FEB2015 31DEC2015 2 . 0.32 . .
0001 01MAR2018 30SEP2018 3 . . 0.43 .
0001 01JAN2019 31DEC2019 3 . . 0.43 .
0002 01JAN2015 31DEC2015 2 . 1.92 . .
0002 01JAN2019 31OCT2019 2 . 1.92 . .
0003 08FEB2014 10MAR2014 1 4.32 . . .
0003 16JUN2015 13JUL2015 1 4.32 . . .
0004 04MAY2016 10MAY2016 3 . . 3.22 .
0004 13SEP2017 15NOV2017 3 . . 3.22 .
0004 09DEC2018 31DEC2018 3 . . 3.22 .
;
In other words I would like to "distribute" the values of variable "Value" across all classes in Class variable.
Thank you in advance
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This will work for the example data:
data work.db1; set work.db; array c (*) class1-class4; c[class]=value; drop value; run;
Arrays are a way of referencing, usually related, variables using one or more numeric index variables. The ARRAY statement creates the reference. Because you already have a variable named Class we couldn't use that as a name so list the names you wanted. The index is placed in parentheses after the array name. I use the [ ] as a style choice to remind myself this is an array.
Arrays can only hold variables of the same type, no mixing numeric and character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This will work for the example data:
data work.db1; set work.db; array c (*) class1-class4; c[class]=value; drop value; run;
Arrays are a way of referencing, usually related, variables using one or more numeric index variables. The ARRAY statement creates the reference. Because you already have a variable named Class we couldn't use that as a name so list the names you wanted. The index is placed in parentheses after the array name. I use the [ ] as a style choice to remind myself this is an array.
Arrays can only hold variables of the same type, no mixing numeric and character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data DB;
input ID :$20. Admission :date09. Discharge :date09. Class Value;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 2 0.32
0001 21FEB2015 31DEC2015 2 0.32
0001 01MAR2018 30SEP2018 3 0.43
0001 01JAN2019 31DEC2019 3 0.43
0002 01JAN2015 31DEC2015 2 1.92
0002 01JAN2019 31OCT2019 2 1.92
0003 08FEB2014 10MAR2014 1 4.32
0003 16JUN2015 13JUL2015 1 4.32
0004 04MAY2016 10MAY2016 3 3.22
0004 13SEP2017 15NOV2017 3 3.22
0004 09DEC2018 31DEC2018 3 3.22
;
proc sort data=db;
by id Admission Discharge class;
run;
proc transpose data=db prefix=class out=want(drop=_name_);
by id Admission Discharge class;
var value;
id class;
run;