Hi Team,
I have raw data in .csv file. The length of all the attributes are defined and given by business but they still would like to identify if any data has exceeded already defined length.
How can i do identify ? What if column A has length greater than 11 in Raw File? How can i filter the observation out?
DATA <dataset1> <dataset2>;
INFILE <fileName>
DLM=',' LRECL=32000 DSD MISSOVER FIRSTOBS=2 TERMSTR=CRLF;
INPUT
A :$11.
B
C :$54.
;
IF _ERROR_=1 THEN OUTPUT <dataset1>;
ELSE OUTPUT <dataset2>;
RUN;
Opps. Check column= option INFILE DLM=',' LRECL=32000 DSD MISSOVER FIRSTOBS=2 TERMSTR=CRLF column=len ; INPUT A :$11. @; put len=; INPUT B @; put len=; INPUT C :$54. @; put len=;
Try make your informats much wider/longer.
But this will make quite an over head for your data import process. A simple matter of filed length should be verified by the sending party.
I might be tempted to read the data with the specification and then turn Proc import loose with a large guessing rows option.. Look at the resulting variable lengths by position in the dataset using either proc contents, Sashelp.vcolumn or Dictionary.columns. If there are variables in the proc import results that are longer then the defined variables then you something to target.
Do
DATA <dataset1> <dataset2>;
INFILE <fileName>
DLM=',' LRECL=32000 DSD MISSOVER FIRSTOBS=2 TERMSTR=CRLF;
INPUT
A :$32.
B
C :$54.
;
IF _ERROR_=1 OR length(A) > 11 THEN OUTPUT <dataset1>;
ELSE OUTPUT <dataset2>;
RUN;
Check length= option: INFILEDLM=',' LRECL=32000 DSD MISSOVER FIRSTOBS=2 TERMSTR=CRLF length=len ; INPUT A :$11. @; put len=; INPUT B @; put len=; INPUT C :$54. @; put len=;
Opps. Check column= option INFILE DLM=',' LRECL=32000 DSD MISSOVER FIRSTOBS=2 TERMSTR=CRLF column=len ; INPUT A :$11. @; put len=; INPUT B @; put len=; INPUT C :$54. @; put len=;
How about using a macro?
%macro do_input(varname,len);
input ___&varname :$%eval(&len+100). @;
length &varname $&len;
&varname = ___&varname;
if length(___&varname) > &len
then &varname._err = 1;
else &varname._err = 0;
drop ___&varname;
%mend;
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.