Okay that makes sense. So I am assuming the following statement causes Start_Date to change to 01JUL2017:
if Start_Date = '01DEC2016'd then do;
Start_Date = '01JUL2017'd;
End_Date = '31JUL2017'd;
output;
end;
What method can be used so that 01DEC2016 is recognized as Winter and 01JUL2017 as summer without compromising the above statement? Thank you for all your help by the way.
The smallest changes to the program would involve consolidating the calculations.
I'm making some assumptions on where I think you are headed. For example, I think you want all the observations, not just those that satisfy the WHERE statement. And I think you want 01DEC2016 output only once. My best guess:
data work.extended;
set prg.discount2016;
if Start_Date = '01DEC2016'd then do;
Promotion = 'Holiday Bonus';
Season = 'Winter';
output;
Promotion = ' ';
Season = ' ';
Start_Date = '01JUL2017'd;
End_Date = '31JUL2017'd;
output;
end;
else if start_date = '01DEC2016'd then do;
season = 'Summer';
output;
end;
else output;
drop Unit_Sales_Price;
run;
Thanks. I included the where statement because I am only wanting to output the 01DEC2016 and 01JUL2017 observations. When I use the method described above only winter is shown not summer.
OK, I know I was guessing a little at the desired results. It's clear now (I think). Here's a rewrite:
data work.extended;
set prg.discount2016;
where Start_Date = '01DEC2016'd;
Promotion = 'Holiday Bonus';
Season = 'Winter';
output;
Promotion = ' ';
Start_Date = '01JUL2017'd;
End_Date = '31JUL2017'd;
season = 'Summer';
output;
drop Unit_Sales_Price;
run;
Thank you soooo much for your help. I have learnt a lot!!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.