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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1308 views
  • 2 likes
  • 6 in conversation