BookmarkSubscribeRSS Feed
rangermollie
Calcite | Level 5

Hi there!

 

I have a dataset that would be very simply formatted in the example below:

 

ID.    Appt_Type.    A1_Date.                 NewDate

1.         5.               01JAN2009

2.         7                11APR 2007

3          6                 22FEB2008

4.         5                 23AUG2004

 

Essentially, I want to create a new column that copies over the date if a certain criteria regarding the appt type is met. I've been using if, then statement but cannot get the date to copy over. 

 

i.e. If appt_type=5, then I want NewDate to equal the value in A1_Date, so NewDate would be 01JAN2009 for ID 1 and 23AUG2004 for ID 4. 

 

Simple question, but I can't seem to find the right code 🙂

2 REPLIES 2
ballardw
Super User

"Cannot get the date to copy" is sort of vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

 

One thing that is possible that you get a value that you don't expect. If the value for Id 1 is 17898 then all you need to do is apply the DATE9. format to the value. Add the data step where you create the value.

   Format Newdate date9.;

 

The basic approach would be below. If your code looks much different from this you really need to share.

if appt_type=5 then Newdate = A1date;
/* or if appt_type is a character value*/
if appt_type='5' then Newdate = A1date;

If you are testing multiple Appt_type values you would use an "Else" before the the comparison for a different type value.

rangermollie
Calcite | Level 5

Oh cool the date9 format worked thanks