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

Hi chouchou,

Others have shown that your INFORMAT is not OK for your purpose. I hope to show you what is happening behind the scenes by examples.

Your value ranges

0 - < 65 , ..... 85 - < 100

produce ERROR. Understanding the reason for this error will get you back to seeking other ways.

First let us stop this ERROR, by a small change in the first and last Range as:

proc format;

invalue $conv

0.001 - < 65 = 'F'

65 -< 75 = 'C'

75 - < 85 = 'B'

85 -  99.999 = 'A'

other = 'Not defined yet ';

run;

I hope this modification may not alter much of your specification. Run this and see that the ERROR is not there.  We will see later why this happened.

Next is, how you will read X - as numeric or character from the input file ?

[1] Let X be numeric as in this input file:

data have;

infile cards truncover;

*input x $3.;

input x;

datalines;

1

2

3

50

57

58

68

69

70

71

78

79

80

82

89

90

91

96

99

100

120

;

run;

Now apply the INFORMAT on X as below:

data want;

   set have;

   x1 = input(x, $conv.);

run;

See the output of the data set, WANT.

proc print data = want;

run;

All your X's are transformed to  'Net defined yet' as only 'other' is applicable for all X's. Why, wait for some time.

[2] Now let X be character Variable.

In the above input file, read X as $3 instead as number and run the following code.

data want;

   set have;

   x1 = input(x, $conv.);

run;

and see the output of the data set WANT:

proc print data = want;

run;

You will see that the LABELS are OK except for 100 and 120 where you are supposed to get 'Not defined yet'. The following show the reasons.

proc sort data = have out = havesort;

by x;

run;

proc print data = havesort;

run;

When X is a character variable, the sorted file shows the order as 1, 100, 120, 2, 3, 50, ...., 96, 99.

Therefore INFORMAT transforms 1 as F, 100 as F, 120 as F, 2 as F, ..., 58 as F, 68 as C and so on.

The lesson is that SAS treats numeric value ranges as character ranges (by default) like '0' - < '65', ...., '85' - < '100' when  INVALUE statement (invalue $convert) is made.

So you can not achieve what you want by your $CONVERT Informat.

Now coming to another way of doing what you want.

Change X to Number in the Input File.

Use the following Format:

proc format;

value numconv

0 - < 65 = 'F'

65 -< 75 = 'C'

75 - < 85 = 'B'

85 -  <100 = 'A'

other = 'Not defined yet ';

run;

Now use the following code to transform X.

data want;

   set have;

   x1 = put(x, numconv.);

run;

proc print data = want;

run;

Message was edited by: MUTHIA KACHIRAYAN

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 15 replies
  • 2698 views
  • 12 likes
  • 7 in conversation