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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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=;

View solution in original post

8 REPLIES 8
LinusH
Tourmaline | Level 20

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.

Data never sleeps
ballardw
Super User

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.  

PGStats
Opal | Level 21

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;

PG
Ksharp
Super User
Check length= option:


INFILE 
DLM=',' LRECL=32000 DSD MISSOVER FIRSTOBS=2 TERMSTR=CRLF
length=len ;
INPUT
A :$11. @;
put len=;

INPUT B @;
put len=;

INPUT C :$54. @;
put len=;


Ksharp
Super User
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=;

Vimal_Kurup
Fluorite | Level 6
I have employed something very similar. Thanks for your time
Kurt_Bremser
Super User

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;
Vimal_Kurup
Fluorite | Level 6
Hi Kurt,

Thanks for your time. I have employed something very similar though not through macro.

I like your solution.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1948 views
  • 2 likes
  • 6 in conversation