BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I've the date variable as follows and it is in character. Based on this field I've to create the new field (KNDEIND) and it should be in character and the rule for the new field is PODVERD-1. Could you please help me understand how can I achieve this in one step?

 

PODVERD KNDEIND
2017-11-25 2017-11-24
4 REPLIES 4
Astounding
PROC Star

If you would store dates as SAS intended, you could simply use:

 

KNDEIND = PODVERD - 1;

 

However, since the requirement is to use character dates, you need to jump through a couple of hoops:

 

KNDEIND = put(input(podverd, yymmdd10.) - 1, yymmddd10.);

 

mkeintz
PROC Star

@Babloo

 

I see that you have over 700 posts to the sas forums, and are labelled a "PROC STAR". I feel that I (and others) are the object of (let's say) a distinct lack  of effort.  Your question is not even accompanied by a report of your own efforts to solve the problem.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

I 2nd @mkeintz response!

 

ballardw
Super User

Since subtraction is generally not a character function, or at least folks don't have a universal standard of what it would mean, the obvious bit is turn it into a numeric, do the subtraction or data adjustment and then put the numeric to a character.

 

kndeind= put ( intnx('day',input(podverd,yymmdd10.),-1),yymmddd10.);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2015 views
  • 8 likes
  • 5 in conversation