BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

Let's say that there is a very big csv file (150 million rows).

I want to import only first 5 rows into sas data set.

I know to do it via proc import 

 

options obs=5;
proc import
datafile="/path/BLL_ISK.csv"
out=want1
dbms=CSV
replace;
delimiter=';';
GETNAMES=YES;
run;
options obs=max;

I don't know how to do it via Infile way.

 

May anyone show?

Please note that I don't want to read all file and then apply option of (obs=5) because it will take very long ru

 

2 REPLIES 2
ballardw
Super User

If you put obs=X , x a number,  on the INFILE statement that is the number of records that will be read assuming you read one line as one record.

 

OBS= option does different things depending on where you are using. You obviously know about the SYSTEM option.

It is also a Dataset option:

Proc print data=sashelp.class (obs=5);
run;

Used this way with a data  set you are telling SAS to only use the first 5 observations in the procedure.

 

Tom
Super User Tom
Super User

If you want to read only 5 observations from a text file that has a header row you need to read 6 lines from the file.

So this code will read the first 10 variables from the first 5 observation of the CSV file.  It will make them all character with a maximum length of 200 bytes so you can take a look at what they might contain.

data want;
  infile "/path/BLL_ISK.csv" dsd dlm=';' firstobs=2 obs=6 truncover;
  input (x1-x10) (:$200.);
run;

If you just want to take a look at the first 6 lines (including the header line) so you can get a sense of what variables there are then just use the LIST statement to dump the lines to the SAS log. 

data want;
  infile "/path/BLL_ISK.csv" obs=6 ;
  input;
  list;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 276 views
  • 0 likes
  • 3 in conversation