Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

infile .csv file in sas with header

I have a csv file which named dataset1.csv and it contains header with 3 variables att1 (character), att2 and att3 (numeric data).

I tried following code

filename test 'C:\Users\1502911\Desktop\Practice\SAS\Dataset';

data dataset1;
    infile test(dataset1.csv) dsd delimiter=',';
    input att1 $ att2 att3;
run;

enter image description here

My desired output is to ignore first row

like image 561
useR Avatar asked Mar 27 '15 03:03

useR


People also ask

Can CSV files have headers?

A header of the CSV file is an array of values assigned to each of the columns. It acts as a row header for the data. Initially, the CSV file is converted to a data frame and then a header is added to the data frame. The contents of the data frame are again stored back into the CSV file.

How do I use Guessingrows in Proc import?

If your data is such that the first 20 rows are not enough, you can use the guessingrows option in proc import: proc import file='text. csv' out=out dbms=csv; guessingrows=300; run; This is useful if you have mixed character and numeric variables for which the first 20 observations are all numeric.


2 Answers

Use firstobs option in infile statement, which would make sure you read the data from second row

http://support.sas.com/documentation/cdl/en/lestmtsref/67407/HTML/default/viewer.htm#n1rill4udj0tfun1fvce3j401plo.htm

data dataset1;
    infile test(dataset1.csv) dsd delimiter=',' firstobs=2;
    input att1 $ att2 att3;
run;
like image 148
in_user Avatar answered Sep 23 '22 15:09

in_user


use proc import is much more convenient, you don't need to manually assign the column name

/** FOR CSV Files uploaded from Unix/MacOS **/
FILENAME CSV "/folders/myfolders/train.csv" TERMSTR=LF;

/** Import the CSV file.  **/
PROC IMPORT DATAFILE=CSV
            OUT=WORK.MYCSV
            DBMS=CSV
            REPLACE;
run;

/** Print the results. **/
PROC PRINT DATA=WORK.MYCSV; RUN;

/** Unassign the file reference.  **/
FILENAME CSV;
run;
like image 36
Yuchao Jiang Avatar answered Sep 20 '22 15:09

Yuchao Jiang