09-25-2016 02:03 PM
I'm a Data Science student at Stockton University in New Jersey, and I'm beginning my journey into SAS. I'm having a hard time trying to get the dates loaded into SAS. I'm using a Linux computer and my code is below:
/** FOR CSV Files uploaded from Unix/MacOS **/
LIBNAME ozone "/folders/myfolders/sasuser.v94/";
FILENAME CSV "/folders/myfolders/My Folders/sasuser.v94/Ozone_data 2015.csv" TERMSTR=LF;
PROC IMPORT DATAFILE="/folders/myfolders/sasuser.v94/Ozone_data 2015.csv"
infile "/folders/myfolders/sasuser.v94/Ozone_data 2015.csv";
input mydate MMDDYY10.;
What happends when I run my code is that the dates don't show up, however, a chart does. Any help would be greatrly appreciated!!
09-25-2016 02:58 PM - edited 09-25-2016 02:59 PM
1) the syntax of FILENAME is:
FILENAME <file_reference> <engine> '...path...' <options>;
You haven't defined the file reference and havn't used 'CSV' as file reference.
I Assume you meant to write:
FILENAME myfile CSV "/folders/myfolders/My Folders/sasuser.v94/Ozone_data 2015.csv" TERMSTR=LF;
2) Does your FILENAME statement refer to the input or to the output file ?
Assuming it is your input CSV file then addapt your code to:
PROC IMPORT DATAFILE=myfile ... etc.
3) In order to help you more please upload few lines from your input CSV file.
4) You are creating DATA OZONE twice: 1) by proc import 2) by data ozone; infile ...
Have you checked yor output after proc import ? I thing the data step is not needed !
09-25-2016 03:41 PM
I would also recommend placing files under myfolders or a subfolder not the sasuser folder.
As indicated you've imported the data twice, use either proc import or the data step.
The data step offers more flexibility, but if you're beginning, I would recommend proc import. Once proc import is done, check the log for the code, which will have generated a data step. This is how you would read the code via data step if you wanted.
09-25-2016 06:54 PM
Thank you both so much!!
My classmate and I are having another issue where we're trying to save a column as an integer. I have the followng code below:
Thank you so much for your help!!
09-25-2016 07:00 PM
Please ask your question in a new thread.
Also include which variable is the issue, what the type is before and what is happening.
Not working doesn't convey very much information, since we don't know what isn't working.
09-26-2016 10:53 AM
One easy diagnostic for PROC Import and delimited files is to read the log immediately after running proc import. If there is an error the SAS error messages are usually pretty good about pointing out where things go wrong.
If the data result looks unexpected but there is no error the log will show the Datastep code SAS generated to read the file. Often type mismatches (you expect numeric but get character or vice versa) will be shown by reading the INFORMAT statements. You can actually copy that code from the log, make changes and rerun.
Note that Proc Import makes guesses about your data. The Guessingrows statement tells how many rows to look at before making those guesses. If a variable is blank for the first few rows, I think 20 is default, then the variable will be character. If it appears to be numeric in the first few rows but latter has character values such can happen with many code type values such as product identifiers, accounts, then the later values will be missing as they are not numeric. A change of Informat from BEST12. or similar to $12. would correct the issue.
Also the variable names will appear in the code as well as notes about column headings that may not have been acceptable.
So to reiterate: when using proc import read the log before going any further with the project. Addressing issues at this step may save LOTS of headaches later.