Question: 4.5 Add code to the data step in 4.4 that will give the variables for each month a better name. The current variable name for
4.5 Add code to the data step in 4.4 that will give the variables for each month a better name. The current variable name for each month is "1", "2", "3", ..... "12". The final data sets should not include any automatic variables that may have been created along the way. The data step code from 4.4 was:
data egg gas milk;
set aveprices_merged;
if Commodity = 'Egg' then output egg;
if Commodity = 'Gas' then output gas;
if Commodity = 'Milk' then output milk;
run;
The code I attempted to use for this problem was:
data egg gas milk; set aveprices_merged; if Commodity = 'Egg' then do; rename 1 = January_Egg 2 = February_Egg 3 = March_Egg 4 = April_Egg 5 = May_Egg 6 = June_Egg 7 = July_Egg 8 = August_Egg 9 = September_Egg 10 = October_Egg 11 = November_Egg 12 = December_Egg; output egg; end; if Commodity = 'Gas' then do; rename 1 = January_Gas 2 = February_Gas 3 = March_Gas 4 = April_Gas 5 = May_Gas 6 = June_Gas 7 = July_Gas 8 = August_Gas 9 = September_Gas 10 = October_Gas 11 = November_Gas 12 = December_Gas; output gas; end; if Commodity = 'Milk' then do; rename 1 = January_Milk 2 = February_Milk 3 = March_Milk 4 = April_Milk 5 = May_Milk 6 = June_Milk 7 = July_Milk 8 = August_Milk 9 = September_Milk 10 = October_Milk 11 = November_Milk 12 = December_Milk; output milk; end; drop _:; run;
However, no data values populate into the datasets, and I receive a syntax error centralized around the renaming variables "1" "2" ... etc. Please advise how to correct.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
