BookmarkSubscribeRSS Feed
dseals23
Fluorite | Level 6

Hello All, 

 

How do I get my SexAgeInfo dataset to output all my information using informat? I have attached the csv file below so you'll know what the output should look like in sas output. Here's my sas code that I am struggling with.  

 

libname Project '/folders/myfolders';

data Project.SexAgeInfo; 
infile '/folders/myfolders/68380_example/SexAgeInfo.csv';    
informat Gender $5.  
         Characteristic $17.
         NumberWorkers2015 $8.
         NumberWorkers2016 $8.
         MedianEarnings2015 $5.
         MedianEarnings2016 $5.;
input Gender 
      Characteristic 
      NumberWorkers2015 
      NumberWorkers2016 
      MedianEarnings2015 
      MedianEarnings2016;
run; 

title "SexAgeInfo DataSet"; 
proc print data=project.sexageinfo; 
run; 

 

 

 

 

 

 

3 REPLIES 3
Reeza
Super User

Are you trying to import data? You talk about 'output' which usually means output from SAS rather than importing data into a system...

Assuming you're trying to import data:

 

1. You missed specifying the delimiter and/or the DSD option on the INFILE statement

2. You're trying to read numeric variables as characters...which is ultimately your choice, but if you plan to do any calculations or summary statistics you'll eventually need to convert them to numeric variables.

3. Your first row is the variable name so you should also uses the FIRSTOBS option to specify your data starts on the second line. 

 

 

I would strongly advise to take the easy route on this. 

 

1. Run a PROC IMPORT on the data and let it generate the code. 

2. Review the log with the code and see what changes you need to make to yours to get it to work. 

 

The PROC IMPORT code looks like:

 

proc import out=want datafile='path to your csv file.csv' dbms=csv replace; run;

 

 

 

 

 

ballardw
Super User

A CSV file does not show what data "should look like in sas". CSV files do not have any data types but SAS differentiates between numeric and character with dates, times and datatime values specially valued numeric variables.

 

If your code, which looks reasonable, isn't providing the result you expect tell us why not.

 

I suspect that the informat you have specified for

         NumberWorkers2015 $8.
         NumberWorkers2016 $8.
         MedianEarnings2015 $5.
         MedianEarnings2016 $5.;

are incorrect as you are using CHARACTER informats, that is what the $ means in this use.

 

I think you might want to use COMMA6. for the Number variables to capture numeric values and best8. for the Median variables if you are looking for numeric values.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 484 views
  • 0 likes
  • 4 in conversation