BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1739 views
  • 0 likes
  • 3 in conversation