DATA Step, Macro, Functions and more

Variable has been defined as both character and numeric

Reply
Contributor
Posts: 72

Variable has been defined as both character and numeric

I have imported several csv files into SAS separately using import data wizard. Now, I would like to merge (combine) them together. But, it seems that the format of one of the variables is not consistant in all the files. Could you please how do I fix this?, or what is wrong with my below code?

 

 

DATA SCOPES.ENTIRE_DATABASE_SCND_CONST;


SET WORK.SCOPESCALCULATIONS_SECONDARYCON1
( rename='COT00503.D_SRVY'n=COT00503_D_SRVY_str in=special )
WORK.SCOPESCALCULATIONS_SECONDARYCON2
( rename='COT00503.D_SRVY'n=COT00503_D_SRVY_str in=special )
WORK.SCOPESCALCULATIONS_SECONDARYCO49
( rename='COT00503.D_SRVY'n=COT00503_D_SRVY_str in=special )
WORK.SCOPESCALCULATIONS_SECONDARYCO54
( rename='COT00503.D_SRVY'n=COT00503_D_SRVY_str in=special )
WORK.SCOPESCALCULATIONS_SECONDARYCO64;


run;

Super User
Posts: 11,343

Re: Variable has been defined as both character and numeric

Posted in reply to almmotamedi

The problem is using the import wizard without noting differences. The wizard makes guesses about your data and using it for multiple files means multiple guesses. If one file has a character value in a column that doesn't appear in others then some files the field is treated as numeric and others as character.

 

If all of the files are of the same structure use the wizard once to generate datastep code and modify it to read all of the datasets with the same characteristics. Check the informats used to see if that makes sense for your data.

Contributor
Posts: 72

Re: Variable has been defined as both character and numeric

I think you did not get my question. I already imported all the files, and I just need to combine them. 

 

Yes, all files have exactly the same structure.

 

Thanks

Super User
Posts: 19,869

Re: Variable has been defined as both character and numeric

Posted in reply to almmotamedi

@ballardw is correct, fix the import/input first then you will have read all the files the same way and will not have this issue.

Ask a Question
Discussion stats
  • 3 replies
  • 296 views
  • 2 likes
  • 3 in conversation