06-02-2017 01:09 PM
I'm a newbie with SAS. I'm trying to convert a CSV file into SAS format. Please find the code and logs below and let me know what is wrong.
OPTIONS NOFMTERR ; %let table=%sysget(v1); %let outfil=%sysget(v2); %macro importa ; proc import datafile="&table" out="&outfil" dbms=csv replace ; run ; %mend importa ; %importa ;
When I run the sas command like:
sas -noterminal -set v1 /mypath/temp.csv -set v2 /mypath /mypath/import.sas
it errors out that:
NOTE: SAS initialization used: real time 0.02 seconds cpu time 0.01 seconds 1 OPTIONS NOFMTERR ; 2 3 %let table=%sysget(v1); 4 %let outfil=%sysget(v2); 5 6 %macro importa ; 7 proc import datafile="&table" out="&outfil" dbms=csv replace ; run ; 8 %mend importa ; 9 %importa ; ERROR: ""/mypath"" is not a valid name. NOTE: PROCEDURE IMPORT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: The SAS System stopped processing this step because of errors. 10
06-02-2017 01:17 PM
It appears that
set v2 /mypath /mypath/import.sas
is getting the value of /mypath for V2 because of the space
V2 would have to resolve to a valid dataset name or LIbrary.dataset name. So no characters other than letters, digits and underscore and cannot start with a digit
set v2 mydatasetname perhaps
06-02-2017 01:46 PM
Thanks for your response. I tried both of these but I still get same error:
sas -noterminal -set v1 /mypath/temp.csv -set v2 test_csv.dataset /mypath/import.sas sas -noterminal -set v1 /mypath/temp.csv -set v2 test_csv /mypath/import.sas
Both returns the same error:
ERROR: ""test_csv"" is not a valid name. ERROR: ""test_csv.dataset"" is not a valid name.
06-02-2017 03:16 PM
Where you use this line the OUT= should be a dataset or library.setname and would not use quotes. I didn't look further than the / the first time.
proc import datafile="&table" out="&outfil" dbms=csv replace ; run ;
proc import datafile="&table" out=&outfil dbms=csv replace ; run ;
but any library referenced needs to exist before the proc import step.
If v2 is supposed to be a data set name then test_csv.dataset would be attempting to create/use a dataset with the NAME of dataset in a library named test_csv.
I haven't done any unix(?) command syntax in over 20 years so if there is an issue with the syntax there I can't help.
06-04-2017 01:49 AM
You shouldn't be trying to read or write anything using the root node of your Unix file system, but perhaps that is just a simplied example for posting the question?
I also noticed that your sample CSV file does NOT have a line with the column names. If that is true then make sure to tell PROC IMPORT that it needs to generates names by itself.
Also make sure that the name of your physical file is in all lowercase letters. The directory name part can contain mixed upper and lowercase letters but the membername part of the filename must be all lowercase. For example you could use "~/MySASData/example1" as the name and SAS would create the dataset EXAMPLE1 using the physical file name of 'example1.sas7bdat' in the 'MySASData' directory under your home directory.
If those don't fix the issue then I think that most likely your problem is that PROC IMPORT is not flexible enough to use a quoted physical name as the name for the output dataset. Perhaps if you just use this simple trick you can get it to work?
OPTIONS NOFMTERR ; %let table=%sysget(v1); %let outfil=%sysget(v2); * Make an empty dataset to create the SYSLAST automatic variable; data "&outfil"; run; proc import out=&syslast replace datafile="&table" dbms=csv ; getnames=no; run;