infile .csv file in sas with header
Asked Answered
V

2

8

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

Variety answered 27/3, 2015 at 3:26 Comment(0)
C
14

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;
Charioteer answered 27/3, 2015 at 4:30 Comment(0)
H
2

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;
Hesson answered 23/3, 2017 at 22:20 Comment(3)
Could you please explain why the "unassign the file reference" code is needed?Sesquicarbonate
Honestly I don't remember. I haven' used SAS since I gave that answer.Hesson
Anyway, thank you for replying :DSesquicarbonate

© 2022 - 2024 — McMap. All rights reserved.