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;
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;
Look at my suggestion in https://communities.sas.com/t5/General-SAS-Programming/How-can-I-get-rid-of-unnecessary-rows-when-I-.... Add a
firstobs=2
option in the infile statement (your original example of the csv did not have a header line).
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.