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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

@anandmgjsa 

 

  1. Can you cut/paste the actual log
  2. The error message you typed states: "variable hardate has..." I'm assuming that's a typo and it should be chardate.
  3. What is the type (char|num) and format date variable on your input data sets?

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 ;

View solution in original post

4 REPLIES 4
AMSAS
SAS Super FREQ

@anandmgjsa 

 

  1. Can you cut/paste the actual log
  2. The error message you typed states: "variable hardate has..." I'm assuming that's a typo and it should be chardate.
  3. What is the type (char|num) and format date variable on your input data sets?

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 ;
anandmgjsa
Fluorite | Level 6

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.

ballardw
Super User

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.

AMSAS
SAS Super FREQ

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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 2650 views
  • 1 like
  • 3 in conversation