DATA Step, Macro, Functions and more

Noob Question- Basic SAS-How to display and INPUT- But need help

Reply
Contributor
Posts: 33

Noob Question- Basic SAS-How to display and INPUT- But need help

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;

 

Super User
Posts: 7,809

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

When you receive ERRORs, it is best to post the log from the offending step(s).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Trusted Advisor
Posts: 1,022

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

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.

Contributor
Posts: 33

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

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 ,.
Super User
Posts: 19,822

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

The log doesn't match the code posted?

 

Please make sure the exact code and log are included. 

Super User
Posts: 7,809

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

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;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,809

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: Noob Question- Basic SAS-How to display and INPUT- But need help

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.

 

.

Ask a Question
Discussion stats
  • 7 replies
  • 133 views
  • 0 likes
  • 5 in conversation