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.
Where does 219 come from?
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;
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.
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
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.