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
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.
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.
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.
@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
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.
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.
sorry for that, will make sure abouit it
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.