BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

Hi,

I have a date value under variable named DATETX like 03/13/2019 and i would like to change that date to 02/27/219. the date value now is MMDDYY10.

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Where does 219 come from?

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

Sometimes I like to find the integer for the date, and then I use the data step to change the value of a date. E.g., I would use the following step to find the number and then do something like 'if datetx = 21621 then datetx=21607' in a data step.

 

data new;
input date  MMDDYY10.  ;
putlog _all_; /*this prints the integer values to the log*/
cards;
03/13/2019 
02/27/2019
;
run;
Kurt_Bremser
Super User

So you want to subtract two weeks? When you need to shift a date by a given amount of a given interval, the intnx() function is the tool of choice.

Dhana18
Obsidian | Level 7

Nope, I have a missing treatment info on 03/13/2019 and I found treatment info on another date 02/27/2019 so I wanted to do some thing like if id="123" then Datetx(treatment date) is 02/27/2019.

I tried  

IF cl_eventid="3716489" then datetx="27Aug2019"d;

it did not give me an error in log but when I proc print the result was not like how I wanted

it was like this

cl_eventid Datetx

3716489     21788

ballardw
Super User

@Dhana18 wrote:

Nope, I have a missing treatment info on 03/13/2019 and I found treatment info on another date 02/27/2019 so I wanted to do some thing like if id="123" then Datetx(treatment date) is 02/27/2019.

I tried  

IF cl_eventid="3716489" then datetx="27Aug2019"d;

it did not give me an error in log but when I proc print the result was not like how I wanted

it was like this

cl_eventid Datetx

3716489     21788


You need to apply a date format to a SAS date value to display properly. Such as DATE9. or MMDDYY10.

If you do not have a default date format assigned and do not specify one in Proc Print then Print will default to BEST.

Try adding

foramt datetx mmddyy10. ;

to your proc print code.

 

If other values are displaying as you want but do not have a date format applied then likely you have a number that only resembles a date and more work is needed.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 484 views
  • 0 likes
  • 5 in conversation