Hi,
I have the below code :
data report_week_oct_dec_data;
set report_04_01_2021(rename=(date = chardate)) report_11_01_2021(rename=(date = chardate))
report_18_01_2021(rename=(date = chardate)) report_25_01_2021(rename=(date = chardate))
report_28_12_2020(rename=(date = chardate))
if not missing(chardate) then date = input(chardate,yymmdd10.);
run;
But this is throwing error. Error is : variable hardate has been defined as bth character and numeric.
Please help.
Assuming it's chardate and the date variable on your input data sets is character in the format "yymmdd10." then the following should work:
data got ;
infile cards;
input date $10. ;
cards;
20210505
20210510
;
data want ;
set got (rename=(date=chardate));
put chardate= ;
date = input(chardate,yymmdd10.);
put date= date= date. ;
run ;
Assuming it's chardate and the date variable on your input data sets is character in the format "yymmdd10." then the following should work:
data got ;
infile cards;
input date $10. ;
cards;
20210505
20210510
;
data want ;
set got (rename=(date=chardate));
put chardate= ;
date = input(chardate,yymmdd10.);
put date= date= date. ;
run ;
in the 1st two files, it is best 32. and in the last three files it's char10.
That's a type 0 error, it is chardate.
i can not paste the log as it's on VDI and i can not copy/snip from that.
You have two issues. First to convert the CHARACTER versions ONLY use the Rename = data set option in the data sets where "date" is character. You are using it on ALL the data sets.
Second, if your "date" is formatted as BEST32 it is not a date either. So I suspect you have something that is numeric and appears as numbers like 20210318. So that needs to be converted to a date instead of just a random number. So you need to tell SAS which data sets DATE is numeric with best32 format so you can make that consistent. You can use the dataset option IN= to create variable that indicates which data set values are coming from.
Assuming your "first two sets" means the first two on the SET statement:
data report_week_oct_dec_data; set report_04_01_2021(In=in1) report_11_01_2021(in=in2) report_18_01_2021(rename=(date = chardate)) report_25_01_2021(rename=(date = chardate)) report_28_12_2020(rename=(date = chardate)) ; if not missing(chardate) then date = input(chardate,yymmdd10.); if in1 or in2 then date = input(put(date,f8. -L),yymmdd10.); format date yymmdd10.; run;
The IN= variables are numeric 1/0 with 1 indicating the current record comes from the data set with that variable. The variables are temporary which means they will not be written to the data set.
PLEASE paste code or log entries into a TEXT box opened on the forum with the </> icon. The main message windows reformat text and can insert non-visible characters that means the code will not run or generate odd errors.
I strongly suspect someone is reading data with Proc Import and not paying attention to details. If you are going to read a bunch of files that are supposed to have the same structure you should be reading the data with a data step to control properties so you don't have to keep "fixing" stuff like this.
Hi @anandmgjsa
As @ballardw points out the input data sets (report_*) have different types for date (numeric for the first 2 and character for the others).
I would recommend that you fix this at the source, you probably have a data|proc step somewhere that is creating the report_* data sets, and they really should be created with the same format.
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.