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

So, I am reviewing some questions for my Base SAS exam this week and I came across this one: 

 

proc format;
value score 

 1 - 50 = 'Fail'
51 - 100 = 'Pass';
run;


proc report data = work.courses nowd;
column exam;
define exam / display format = score.;
run;


The variable EXAM has a value of 50.5.


How will the EXAM variable value be displayed in the REPORT procedure output?
A. Fail
B. Pass
C. 50.5
D. . (missing numeric value)

 

I realize the answer is C, b/c the proc format does not include 50.5, but my question is HOW would you rewrite this program to be inclusive of decimals? Would be as simple as adding .00 to the 100.00 and 50.00, etc. 

 

Also, on a somewhat unrelated notes, any tips on remembering the difference and uses of FORMAT and INFORMAT statements? Especially when inputting data. 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

A small illustration:

 

/*Redefine to make in inclusive*/

proc format;
value score 

 1 - <51 = 'Fail'
51 - 100 = 'Pass';
run;

data formatted_n;
do n=1 to 112 by 0.5;
format=put(n,score.);
output;
end;
run;

 

 50.5 is less than 51, so Fail 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

like this?

 


proc format;
value score 

 1 - <51 = 'Fail'
51 - 100 = 'Pass';
run;
BenCBanks
Fluorite | Level 6

Perhaps that would do it. Does the < and > sign allow for exclusivity w/decimals when dealing with ranges? In other words, would 50.5 now be classified as "fail"? 

novinosrin
Tourmaline | Level 20

A small illustration:

 

/*Redefine to make in inclusive*/

proc format;
value score 

 1 - <51 = 'Fail'
51 - 100 = 'Pass';
run;

data formatted_n;
do n=1 to 112 by 0.5;
format=put(n,score.);
output;
end;
run;

 

 50.5 is less than 51, so Fail 

BenCBanks
Fluorite | Level 6

Got it. Did not realize that the < > allowed for exclusivity and that w/o them you would be simply looking at the whole number. Thanks! 

Tom
Super User Tom
Super User

@BenCBanks wrote:

 

... 

Also, on a somewhat unrelated notes, any tips on remembering the difference and uses of FORMAT and INFORMAT statements? Especially when inputting data. 


FORMATs convert values to text and INFORMATs convert text to values.

You use INFORMATs with INPUT statement and INPUT() function.

You use FORMATs with PUT statement and PUT() function.

 

So you use an INformat when INputting the data. You attach a format when you want to tell SAS how to display the value.

 

Remember that SAS already knows how to read and write numbers and character strings. So in most cases you do not need etther an INFORMAT or a FORMAT. The most obvious case where they are important is with DATE, TIME and DATETIME values since the text used to display those looks nothing like the value that is stored.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2606 views
  • 0 likes
  • 3 in conversation