DATA Step, Macro, Functions and more

SAS Date

Reply
New Contributor
Posts: 2

SAS Date

Hello Everyone,

 

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"
OUT=ozone
DBMS=CSV
REPLACE
RUN;

DATA ozone;
infile "/folders/myfolders/sasuser.v94/Ozone_data 2015.csv";
input mydate MMDDYY10.;
RUN;

 

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!!


SASProblem.png
Trusted Advisor
Posts: 1,574

Re: SAS Date

[ Edited ]
Posted in reply to matthewjkancy

Few remarks:

 

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 !

     

    

Super User
Posts: 19,832

Re: SAS Date

Posted in reply to matthewjkancy

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. 

New Contributor
Posts: 2

Re: SAS Date

Posted in reply to matthewjkancy

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:

 

DATA ozoneintegers;
SET ozone.ozone;
Daily.Max.8.hour.Ozone.Concentration=input(Daily.Max.8.hour.Ozone.Concentration,7.);
DAILY_AQI_VALUE=input(DAILY_AQI_VALUE,4.);
DAILY_OBS_COUNT=input(DAILY_OBS_COUNT,4.);
PERCENT_COMPLETE=input(PERCENT_COMPLETE,10.);
RUN;

 

Thank you so much for your help!!

Super User
Posts: 19,832

Re: SAS Date

Posted in reply to matthewjkancy

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.

Super User
Posts: 11,343

Re: SAS Date

Posted in reply to matthewjkancy

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.

Ask a Question
Discussion stats
  • 5 replies
  • 435 views
  • 0 likes
  • 4 in conversation