BookmarkSubscribeRSS Feed
matthewjkancy
Calcite | Level 5

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
5 REPLIES 5
Shmuel
Garnet | Level 18

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 !

     

    

Reeza
Super User

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. 

matthewjkancy
Calcite | Level 5

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

Reeza
Super User

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.

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1142 views
  • 0 likes
  • 4 in conversation