Hi,
I have a file with around 58 variables (Numeric and Char). While using "if-then" statement on the char variables, since the column length is small, i am not able to match the string (used in "if") with the value in observation.
How can i resize all the character variables while importing the file in SAS?
I don't understand you issue?
Is that your char columns are truncated, or is it the if-statement itself?
Why don't you just define appropriate length for your char variables?
If you just run Proc import it is likely that depending on your options that the variables were not imported with the full length.
I generally take a look at the code generated by proc import, either in the log or by using F4 to recall the code immediately after running import, and look at the INFORMAT statements generated. Those will indicate the lengths of the variables as read. If any are too short modify the code by increasing the values in the informat (and Format if you keep them, often not needed if leaving the text as read).
SAVE the data step code and rerun.
If you inherited a process with data step code, time to confirm that the lengths declared are correct.
A brief example of a possible data step generated by proc import:
data MIECHV13.MSGDEMO ;
infile msg delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat Line best32. ;
informat Data_Source $2. ;
informat Program_ID $1. ;
informat CaseNumber $9. ;
informat FamilySiteIdentifier $9. ;
informat Relationship $10. ;
informat Gender $6. ;
informat DOB mmddyy10. ;
informat Race $16. ;
informat Ethnicity $25. ;
/* a corresponding input statement would follow*/
Suppose that my race field, potentially containing ALL values of Black, White, Asian, Native American / Alaska Native and/or Hawiian or Pacific Islander. The import code generated a length of 16 due to a small value of guessingrows and/or my first data didn't have a combination of all of the values. So I count up how many characters are needed, or possibly have a field description from the data source and change the
Informat Race $16;
to
Informat Race $80.;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.