DATA Step, Macro, Functions and more

data step error

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

data step error


 

Please help in SAS...

(this is the data from the dat file) The info for golf.dat is the one below

Kapalua Plantation 18 73 7263 125.00

Pukalani                18 72 6945 55.00

Sandlewood          18 72 6469 35.00

Silversword            18 71    .    57.00

Waiehu Municipal  18 72 6330 25.00

Grand Waikapa      18 72 6122 200.00

Read the data contained in the golf.datPreview the documentView in a new window file using a DATALINES statement into a permanent SAS data set called question02. The data in each record are in order: golf course (name), number of holes (holes), par (par), total yardage (yardage), and greens fees (fees). Print the resulting SAS data set ensuring that the output is centered, your page size is no larger than 58 lines, and the linesize no longer than 80 characters. When you print the data set, do what you need to do, to make it look (exactly) like this:

That is: (1) double space your output, (2) label the variables as in the above output, (3) title the output as it appears above, (4) suppress the printing of the observation number, and (5) make sure that the yardage contains a comma (e.g., 7,263) and the fees are preceded by a dollar sign (e.g., $125.00).

 

 

The program I wrote

 

libname perm "C:\temp";

data perm.question02:

infile datalines dsd ;

informat total_yardage fees;

input  golfcourse $ holes par total_yardage comma5. fees comma10.2;

datalines;

Kapalua Plantation 18 73 7263 125.00

Pukalani                18 72 6945 55.00

Sandlewood          18 72 6469 35.00

Silversword            18 71    .    57.00

Waiehu Municipal  18 72 6330 25.00

Grand Waikapa      18 72 6122 200.0

;

run;


Double - double spaces the printed output.

Noobs - suppresses the observation number in the output.

Program2

titile "Question#2";

proc print data =question02 double noobs;

var golfcourse par holes   total_yardage fees ;

label par ='Par' holes='No. of holes' total_yardage='Yardage' fees='Greens_Fees';

format   total_yardage comma5. fees comma10.2;

run;

I am getting error


Accepted Solutions
Solution
‎01-31-2017 04:57 AM
Super User
Posts: 5,516

Re: data step error

Posted in reply to venkatnaveen

There are several additional issues to attend to.  Definitely refer to the right data sets.  But on top of that ...

 

When reading the data, DSD is incorrect.  That informs SAS that commas should be used as delimiters, instead of spaces.  Just remove it.

 

The INFORMAT statement is unnecessary.  Since no informats are actually specified, it does nothing.

 

The COMMA informats within the INPUT statement are also unnecessary.  The data contains no commas and can mostly be read in simple fashion by scanning the lines of data from left to right.  (Later when printing, FORMATS are needed.  More on that later.)

 

The GOLFCOURSE values will be incorrect.  SAS will truncate them to 8 characters.  Also, to read a single embedded blank as part of the name of the golf course, you will need 2 blanks between the GOLFCOURSE and the HOLES within the datalines.  Additional measures are still needed to read that data.  First, add a LENGTH statement before the INPUT statement:

 

length golfcourse $ 20;

 

Then within the INPUT statement, instruct SAS to look for 2 blanks, not 1, to mark the end of GOLFCOURSE:

 

input golfcourse $ & par ...

 

That should take care of the DATA step.  PROC PRINT still has an issue or two.

 

To get labels to print as column headings instead of variable names, you need to add an option to the PROC PRINT statement.  Either LABEL or the SPLIT= option would have that effect.  Since one of the labels needs to be split across two lines, SPLIT= would be better because it would give you control over splitting the label.  So if you add this to the PROC PRINT statement:

 

split='*'

 

to match that you would use these labels:

 

label holes='No. of*holes'

 fees='Greens*Fees';

 

Finally, you're using the wrong format for FEES.  To get dollar signs to print, you need a DOLLAR format:

 

format fees dollar7.2;

 

Give it a shot, see how close you get.

View solution in original post


All Replies
SAS Super FREQ
Posts: 8,868

Re: data step error

Posted in reply to venkatnaveen
Hi:
This looks like homework for a class. Is it?
cynthia
Frequent Contributor
Posts: 89

Re: data step error

Posted in reply to Cynthia_sas

Yes the task given and I solkved that way.I am unable to get the o/p

Trusted Advisor
Posts: 1,584

Re: data step error

[ Edited ]
Posted in reply to venkatnaveen

Here is your first program.

Statement should end with semicolon ( ) not by colon ( : );

The INFORMAT statement is uncomplete; You can cancel it as you defined the informats within the INPUT statement.

libname perm "C:\temp";
data perm.question02:   /* should be ; not : */
infile datalines dsd ;
informat total_yardage fees;
input  golfcourse $ holes par total_yardage comma5. fees comma10.2;
datalines;
Kapalua Plantation 18 73 7263 125.00
Pukalani                18 72 6945 55.00
Sandlewood          18 72 6469 35.00
Silversword            18 71    .    57.00
Waiehu Municipal  18 72 6330 25.00
Grand Waikapa      18 72 6122 200.0
;
run;

Your second program is below.

You created dataset  perm.question02, that is in library perm but you are trying to read

the dataset from work, the temporary, default library:

 

titile "Question#2";
proc print data = question02 double noobs;
var golfcourse par holes   total_yardage fees ;
label par ='Par' holes='No. of holes' total_yardage='Yardage' fees='Greens_Fees';
format   total_yardage comma5. fees comma10.2;
run;

I see no other errors.

Solution
‎01-31-2017 04:57 AM
Super User
Posts: 5,516

Re: data step error

Posted in reply to venkatnaveen

There are several additional issues to attend to.  Definitely refer to the right data sets.  But on top of that ...

 

When reading the data, DSD is incorrect.  That informs SAS that commas should be used as delimiters, instead of spaces.  Just remove it.

 

The INFORMAT statement is unnecessary.  Since no informats are actually specified, it does nothing.

 

The COMMA informats within the INPUT statement are also unnecessary.  The data contains no commas and can mostly be read in simple fashion by scanning the lines of data from left to right.  (Later when printing, FORMATS are needed.  More on that later.)

 

The GOLFCOURSE values will be incorrect.  SAS will truncate them to 8 characters.  Also, to read a single embedded blank as part of the name of the golf course, you will need 2 blanks between the GOLFCOURSE and the HOLES within the datalines.  Additional measures are still needed to read that data.  First, add a LENGTH statement before the INPUT statement:

 

length golfcourse $ 20;

 

Then within the INPUT statement, instruct SAS to look for 2 blanks, not 1, to mark the end of GOLFCOURSE:

 

input golfcourse $ & par ...

 

That should take care of the DATA step.  PROC PRINT still has an issue or two.

 

To get labels to print as column headings instead of variable names, you need to add an option to the PROC PRINT statement.  Either LABEL or the SPLIT= option would have that effect.  Since one of the labels needs to be split across two lines, SPLIT= would be better because it would give you control over splitting the label.  So if you add this to the PROC PRINT statement:

 

split='*'

 

to match that you would use these labels:

 

label holes='No. of*holes'

 fees='Greens*Fees';

 

Finally, you're using the wrong format for FEES.  To get dollar signs to print, you need a DOLLAR format:

 

format fees dollar7.2;

 

Give it a shot, see how close you get.

Frequent Contributor
Posts: 89

Re: data step error

Posted in reply to Astounding

Thanks a lot.

Superb..!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 179 views
  • 1 like
  • 4 in conversation