BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
talzy7
Calcite | Level 5

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.

Astounding
PROC Star

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;

talzy7
Calcite | Level 5

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.

Astounding
PROC Star

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;

talzy7
Calcite | Level 5

Thank you soooo much for your help. I have learnt a lot!!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 19 replies
  • 1498 views
  • 0 likes
  • 4 in conversation