BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
venkatnaveen
Obsidian | Level 7

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

5 REPLIES 5
Cynthia_sas
SAS Super FREQ
Hi:
This looks like homework for a class. Is it?
cynthia
venkatnaveen
Obsidian | Level 7

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

Shmuel
Garnet | Level 18

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.

Astounding
PROC Star

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.

venkatnaveen
Obsidian | Level 7

Thanks a lot.

Superb..!

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
  • 5 replies
  • 1485 views
  • 1 like
  • 4 in conversation