BookmarkSubscribeRSS Feed
SixUnder
Obsidian | Level 7

I am new to SAS, and i have a problem I am trying to resolve. I have parts of it done but i keep getting errors and i thought why not post it on here, most i can do is get laughed at because i dont know SAS.

 

Problem.

 

Write a SAS® program to access the Microsoft® Excel® spreadsheet and select these four specific data items:

  • Male, worked full-time with earnings of $55,000 to $100,000 or more population estimate
  • Female, worked full-time with earnings of $55,000 to $100,000 or more population estimate
  • Male, worked full-time other category with earnings of $55,000 to $100,000 or more population estimate
  • Female, worked full-time other category with earnings of $55,000 to $100,000 or more population estimate

Create a comma-delimited raw data file to store information that includes gender, earnings categories, and number of individuals in each category for only the data indicated above.

 

What i have done so far is attached in a comma delimited file as far as my excel sheet, I am not getting how to list these out and retrieve the data in a table. So far the code below is the best i have come up with for this resolution. Any help would be grand and appreciated.

 

Thanks!

 

data Auglaize;

    infile ' /home/ktylu10/sasuser.v94/Week 2 Individual Auglaize County.csv’ dlm=',' firstobs=2;

    input ? : $char# ? : $char# ? : $char#  ? : $char#;

run;

proc print data=Auglaize;

run;

 

7 REPLIES 7
mkeintz
PROC Star

If you're trying to read in a csv file, in which the first row are variable/column names, I'd suggest learning about proc import.  Then you can go on to the subsequent tasks.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SixUnder
Obsidian | Level 7
data Auglaize;
    infile '/home/ktylu10/sasuser.v94/Week 2 Individual Auglaize County Jason.csv’ dlm=',' firstobs=2;
    Input Gender :$6. Income :$20. Fulltime 8:$15 comma8.0;

run;

proc print data=Auglaize;

run;
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 data Auglaize;
57 infile '/home/ktylu10/sasuser.v94/Week 2 Individual Auglaize County Jason.csv’ dlm=',' firstobs=2;
58 Input Gender :$6. Income :$20. Fulltime 8:$15 comma8.0;
59
60 run;
61
62 proc print data=Auglaize;
63
57 infile '/home/ktylu10/sasuser.v94/Week 2 Individual Auglaize County Jason.csv’ dlm=',' firstobs=2;
_
23
ERROR 23-2: Invalid option name ,.
Reeza
Super User

The log doesn't match the code posted?

 

Please make sure the exact code and log are included. 

Kurt_Bremser
Super User

The closing quote at the end of your infile name is not a standard single quote. Try this instead:

data Auglaize;
    infile '/home/ktylu10/sasuser.v94/Week 2 Individual Auglaize County Jason.csv' dlm=',' firstobs=2;
    Input Gender :$6. Income :$20. Fulltime 8:$15 comma8.0;
run;

 

Kurt_Bremser
Super User

I uploaded your .csv (which is in DOS format with CRLFs, something you should correct if you try to read on UNIX) to my UNIX server using text mode (converts the CRLF to LF) and ran this:

data auglaize;
infile '$HOME/sascommunity/auglaize_county_2.csv' dlm=',' firstobs=2 ;
input gender :$6. income :$20. fulltime other;
run;

proc print data=auglaize noobs;
run;

The result:

gender        income        fulltime    othe

Male      55000 to 64999      1041       203
Male      65000-74999          712       199
Male      75000-99999         1168       159
Male      100000 or more        39       112
Female    55000 to 64999       572       241
Female    65000-74999          230       104
Female    75000-99999          213        91
Female    100000 or more       125        39

Note that I replaced the stupid blanks in the filename with underlines. Is much easier to handle during file operations on the OS level.

ballardw
Super User

1) I think the Forum treats that a xls as when I do a save target as from the browser the file name looks ends in XLS.

 

 

I would recommend using the import wizard the first time to bring the data into sas. Look in the File menu for Import data. That will generate a program to read the data that will appear in the Log. You could copy the text from the log to the editor and edit as needed.

It will look something like:

data WORK.AUGL                                    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile '<path>\Auglaize County 2.csv' delimiter = ',' MISSOVER DSD lrecl=32767  firstobs=2 ;
   informat Gender $7. ;
   informat Income $14. ;
   informat Fulltime best32. ;
   informat Other best32. ;
   format Gender $7. ;
   format Income $14. ;
   format Fulltime best12. ;
   format Other best12. ;
input
            Gender $
            Income $
            Fulltime
            Other
;
if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
run;

You can save the program to run later as well.

 

.

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
  • 7 replies
  • 962 views
  • 0 likes
  • 5 in conversation