I am running SAS Studio 3.6 Basic Edition. I am a beginner at SAS and I can't get past this error that I've been having. I have the code below and the file is in the correct place. I created a folder under the "my folders" in the sidebar called "Exercises" and under that I created a folder called "data". It seems that it is not reading the file but I'm not sure why because the path is correct (to my knowledge).
Any ideas? I have already tried googling and most of the results with this error have to do with _WEBOUT which I don't believe is my problem.
DATA SALARIES;
INFILE '/Exercises/data/AAUP_data.txt';
INFILE SALARIES delimiter=',';
INPUT FICE College_Name $ State $ Type $ Average_Salary_Full
Average_Salary_Assoc Average_Salary_Asst Average_Salary_All
Average_Comp_Full Average_Comp_Assoc Average_Comp_Asst Average_Comp_All
Number_of_Professors_Full Number_of_Professors_Assoc
Number_of_Professors_Asst Number_of_Instructors Number_of_Faculty_All
;
RUN;
PROC PRINT;
RUN;
I appreciate the help.
Your second infile statement is meant to be used in conjunction with a filename statement.
If your SALARIES infile is meant to be the text file stored at '/Exercises/data/AAUP_data.txt', then there are two ways you could write this:
FILENAME SALARIES '/Exercises/data/AAUP_data.txt';
DATA SALARIES;
INFILE SALARIES delimiter=',';
INPUT FICE College_Name $ State $ Type $ Average_Salary_Full
Average_Salary_Assoc Average_Salary_Asst Average_Salary_All
Average_Comp_Full Average_Comp_Assoc Average_Comp_Asst Average_Comp_All
Number_of_Professors_Full Number_of_Professors_Assoc
Number_of_Professors_Asst Number_of_Instructors Number_of_Faculty_All
;
RUN;
PROC PRINT;
RUN;
or simply
DATA SALARIES;
INFILE '/Exercises/data/AAUP_data.txt' delimiter=',';
INPUT FICE College_Name $ State $ Type $ Average_Salary_Full
Average_Salary_Assoc Average_Salary_Asst Average_Salary_All
Average_Comp_Full Average_Comp_Assoc Average_Comp_Asst Average_Comp_All
Number_of_Professors_Full Number_of_Professors_Assoc
Number_of_Professors_Asst Number_of_Instructors Number_of_Faculty_All
;
RUN;
PROC PRINT;
RUN;
Related
How to generate test data with no input data in SAS?
Why don't you use one of the example datasets in the SASHELP library?
For instance
proc print data=help.class;
run;
More examples can be found here
Another alternative is to use inline data,
like in
data person;
infile datalines delimiter=',';
input name $ dept $;
datalines;
John,Sales
Mary,Acctng
;
run;
If you realy want to use no input at all, use a data step with a loop.
like in
data whatever;
do Key = -99 to 99 by 2;
Square= Key*Key;
Value= rand("Uniform");
output;
end;
run;
There is the sashelp library, but if you are looking for something different - check out the Bizarro Ball data here: https://github.com/allanbowe/BizarroBall
To import, just run the following:
filename bizarro url
"https://raw.githubusercontent.com/allanbowe/BizarroBall/master/bizarroball.sas";
%inc bizarro;
I have a dataset that I'm trying to work with
My code is
DATA AlbumData;
INFILE '/folders/myfolders/Data.txt' DLM=',';
INPUT Movie $ Director $ Date ANYDTDTE10. Budget BoxOffice Genre $;
RUN;
My issue is the first line of the .txt file I'm importing has these same headings. How do I work around that?
Try adding the FIRSTOBS=2 option to the INFILE line. This will tell the file pointer to start on line 2.
DATA AlbumData;
INFILE '/folders/myfolders/Data.txt' DLM=',' FIRSTOBS=2;
INPUT Movie $ Director $ Date ANYDTDTE10. Budget BoxOffice Genre $;
RUN;
I'm trying to import a sas dataset into SAS, using a data step. It is tab-delimited. Here is my code so far. When I go to run the data, it runs but then the output data looks all wrong. Is there a better way to do this?
data medicare;
infile '/folders/myfolders/sasuser.v94/medicare.sas' dlm='09'X;
input NPI NPPES_CREDENTIALS $ NPPES_PROVIDER_GENDER $ NPPES_ENTITY_CODE $ NPPES_PROVIDER_ZIP $ NPPES_PROVIDER_STATE $ PROVIDER_TYPE $ MEDICARE_PARTICIPATION_INDICATOR $ PLACE_OF_SERVICE $ HCPCS_CODE $ HCPCS_DRUG_INDICATOR $ LINE_SRVC_CNT BENE_UNIQUE_CNT BENE_DAY_SRVC_CNT AVERAGE_MEDICARE_ALLOWED_AMT STDEV_MEDICARE_ALLOWED_AMT AVERAGE_SUBMITTED_CHRG_AMT STDEV_SUBMITTED_CHRG_AMT AVERAGE_MEDICARE_PAYMENT_AMT sSTDEV_MEDICARE_PAYMENT_AMT;
run;
If you are looking for a beginner-friendly approach, you can first run proc import. SAS will guess the correct data types, lengths, etc. Here is an example:
filename imp "C:\Users\&sysuserid.\Documents\xxx.txt" encoding="cp1252" TERMSTR=CRLF;
proc import datafile=imp
out=imported_table
dbms=dlm
replace;
delimiter='09'x;
getnames=yes;
guessingrows = 1000000;
run;
Then, copy the data step code SAS prints into the log and update it (if needed).
My input file looks like this:
FCODE,AIRPORT,TDATE,CHILD,ADULT,ECAR,FCAR
IA06100,CDGWE,01APR2000,8,85,3328,11730
IA05900,CDG,01APR2000,8,85,2392,8415
IA07200,FRA,01APR2000,10,97,1720,5432
IA04700,LHR,01APR2000,14,120,2576,7320
I want to read this file and create a dataset, where the TDATE file is formatted into mm/dd/yyyy. The following is my base sas code:
data test;
infile "C:\SAS Training\testfile.txt" firstobs=2 dlm=',';
input FCODE $ AIRPORT $ TDATE $ CHILD ADULT ECAR FCAR;
format tdate MMDDYYYY10.;
run;
But I am getting ERROR 48-59: The informat $MMDDYY was not found or could not be loaded. Essentially I want to convert the date "01APR2000" in the input file to "04/01/2000" in the dataset.
Thanks
Try this below. TDATE is a date (special case of numeric in SAS) so no following $ in input statement. You also make some confusion between informat (how SAS reads raw data and convert it) and format (how SAS displays data).
data test;
infile "C:\SAS Training\testfile.txt" firstobs=2 dlm=',';
input FCODE $ AIRPORT $ TDATE CHILD ADULT ECAR FCAR;
informat tdate DATE9.;
format tdate DDMMYY10.;
run;
You need to use proper INFORMAT
TDATE :date.
Note the :
Given the csv:
Cat,,9
Dog,,10
Egg,,11
And the code:
DATA database ;
INFILE '/path/to/data' dlm=',' missover;
INPUT
animal $
missing $
number
;
RUN;
The output I get is:
animal missing number
Cat 9
Dog 10
Egg 11
How can I get SAS to recognize the missing value, so that my output table is like the one below?
animal missing number
Cat 9
Dog 10
Egg 11
You just need to include dsd in your infile statement as this signifies that SAS should treat two consecutive commas as a missing value. You can read more information here:
DATA database ;
INFILE '/path/to/data' dlm=',' missover dsd;
INPUT
animal $
missing $
number
;
RUN;