Reputation: 51
I am rearranging some data to run in a linear regression and used the code below to change. When I look at the new dataset however the New Names are incomplete. For example Day11 shows are Day1, Day14 as Day1, Day20 as Day2 ect. Where is my code causing this problem?
Data EMU116Linear;
Set EMU116;
TumorVolume = Day0; Day = "Day0"; output;
TumorVolume = Day3; Day = "Day3"; output;
TumorVolume = Day7; Day = "Day7"; output;
TumorVolume = Day9; Day = "Day9"; output;
TumorVolume = Day11; Day = "Day11"; output;
TumorVolume = Day14; Day = "Day14"; output;
TumorVolume = Day16; Day = "Day16"; output;
TumorVolume = Day18; Day = "Day18"; output;
TumorVolume = Day21; Day = "Day21"; output;
drop Day0 Day3 Day7 Day9 Day11 Day14 Day16 Day18 Day21 TumorWeightDay21;
Run;
Upvotes: 1
Views: 73
Reputation: 107587
SAS will truncate character values to the variable's designated length. Since you do not explicitly specify length, the very first assignment of Day0 designates the length of the new Day variable to 4 characters. Afterwards, any supplied, longer value to Day variable will truncate to 4 (i.e., Day11
to Day1
). To accommodate 5 characters and to initialize new variables use length
directive:
Data EMU116Linear;
Set EMU116;
length TumorVolume Day $5;
...
run
However, from your code and desired result a better less repetitive solution may be proc_transpose
to reshape your wide data to long format:
proc sort data=EMU116Linear;
by Treatment Treatment2 TreatCode Mouse;
run;
proc transpose
data=EMU116Linear
out=EMU116;
by Treatment Treatment2 TreatCode Mouse;
run;
data EMU116;
set EMU116;
rename col1=TumorVolume
_name_=Day;
run;
Upvotes: 1