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

i have a date variable which is in numeric and in "2009-02-17" format. i am calculating flag variable with char date in "2009-02-15" and converting it to numeric like below

 

data ae053;
set ae052;
format SVSTD date9.;
SVSTD = input ( SVSTD, MMDDYY10.);
if ASTD < SVSTD then flag= "N";
else flag= "Y";
run;

 

I still get error in the log.

 

can anyone help me in this

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post example test data in the form of a datastep whenever you post a question.  This helps us see the data as you have it.  Otherwise we are guessing.  

data want;
  svstd="2009-02-17";
  svsstd_num=input(svstd,yymmdd10.);
  format svsstd_num date9.;
run;

Note that you can't put a numeric value back into the character variable (i.e. svstd is character, this will just return a character result.).  Put the result of the conversion into a numeric variable.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

If svstd is already a SAS date variable (numeric, date format), then you can't use it as argument to the input() function, as that expects a character value.

Please supply your example data in a data step for testing, and your expected result.

vraj1
Quartz | Level 8
pt svdt ASTDT flag
101 2009-02-17 2009-02-09 N
102 2009-08-03 2009-08-02 Y
103 2009-02-09 2009-02-10 N

 

In this case SVDT is in char and format and length as 10.

ASDT is numeric and format and length as 10.

DanielSantos
Barite | Level 11

Hi.

 

You've got the informat wrong

 

It should be YYMMDD10., not MMDD10.

 

Daniel Santos @ www.cgd.pt

Kurt_Bremser
Super User

@vraj1 wrote:
pt svdt ASTDT flag
101 2009-02-17 2009-02-09 N
102 2009-08-03 2009-08-02 Y
103 2009-02-09 2009-02-10 N

 

In this case SVDT is in char and format and length as 10.

ASDT is numeric and format and length as 10.


You cannot change the type of a variable, you have to create a new one and remove the old:

data have;
input pt svdt :$10. astdt :yymmdd10. flag :$1.;
format astdt yymmddd10.;
cards;
101 2009-02-17 2009-02-09 N
102 2009-08-03 2009-08-02 Y
103 2009-02-09 2009-02-10 N
;
run;

data want;
set have (rename=(svdt=svdt_old));
format svdt yymmddd10.;
svdt = input(svdt_old,yymmdd10.);
drop svdt_old;
run;

proc print data=want;
run;

The result looks like this:

Obs     pt         astdt    flag          svdt

 1     101    2009-02-09     N      2009-02-17
 2     102    2009-08-02     Y      2009-08-03
 3     103    2009-02-10     N      2009-02-09
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post example test data in the form of a datastep whenever you post a question.  This helps us see the data as you have it.  Otherwise we are guessing.  

data want;
  svstd="2009-02-17";
  svsstd_num=input(svstd,yymmdd10.);
  format svsstd_num date9.;
run;

Note that you can't put a numeric value back into the character variable (i.e. svstd is character, this will just return a character result.).  Put the result of the conversion into a numeric variable.

Kurt_Bremser
Super User

And, for the future:

 

"I still get error in the log."

 

is NOT helpful. Post at least the ERROR message text, but much better is to post the log including the whole step where the ERROR happened.

vraj1
Quartz | Level 8

sorry for that, will make sure abouit it

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 960 views
  • 2 likes
  • 4 in conversation