Reputation: 5413
How can I read into a SAS a .txt file of the form:
"A","B","C",...
n1,n2,n3...
m1,m2,m3...
p1,p2,p3...
.
.
.
Where n*, m*, p* etc. represent numeric values. Do I actually need to specify all of the headers like
INPUT A B C D E F G ...
Or is there a more concise way?
Upvotes: 0
Views: 5743
Reputation: 9618
To read a delimited text file into a SAS data set, use PROC IMPORT:
proc import datafile='<path to delimited file>'
out=mydata /* SAS data set to create */
dbms=dlm
replace;
delimiter=',' /* Specify the delimiter */;
getnames=yes; /* Get variable names from first row */
run;
This is the same code that is actually executed when you use the Import Data Wizard.
Upvotes: 0
Reputation: 7602
Another way is to use the Import Data wizard from the file menu. Just make sure you choose Delimited File and put ',' as the delimiter from the options button in the next screen. Using the wizard doesn't always create the correct field types, however if you press the F4 key from within the Editor once the import has finished, it will recall the full code it used (including the input statement for all the column headers). You can then edit the code to suit.
Upvotes: 1
Reputation: 11765
If you really want to name the variables A, B, C, ...
it's a little bit trickier, but if you're happy naming them something like var1, var2, ...
then this will work:
data test;
infile 'data.txt' dlm=',';
input var1-var5;
run;
SAS automatically generates variables var1, var2, var3, var4, var5
when you say var1-var5
.
Upvotes: 3