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

Hi, I have this lookup table (range), which I intend to use as a format for another table (have).

 

 

data range;
input low high desc $8.;
cards;
-999999 1 Low
2 3 Medium
4 999999 High
;
run;

 

data have;
input num;
cards;
-1
0
5
;
run;

 

I'd also prefer for the low range, to include all values <= 1, and the high range to include all values > 4.

 

How is this possible?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here are changes to make, for this to be suitable for creating a format:

 

data range;
input start end label $8.;

if label='Low' then HLO='L';

else if label='High' then HLO='H';

fmtname='Range';
cards;
-999999 1 Low
2 3 Medium
4 999999 High
;

 

Then you can create a format using:

 

proc format cntlin=range;

run;

 

And you can use the format when processing HAVE, by adding:

 

format num range.;

 

A few notes:

 

  • The variable names have been changed.  START, END, LABEL, and FMTNAME are required names.
  • Note that you have gaps here, for non-integer values.
  • When HLO="L", that tells PROC FORMAT to ignore the START value, and consider "Low" to be the start of the range.
  • Similarly, when HLO="H", that tells PROC FORMAT to ignore the END value, and consider "High" to be end of the range.
  • The name of the format (range.) comes from the FMTNAME variable, not from the name of the CNTLIN= data set.

 

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can use LOW and HIGH to represent below and above respectively, as this code demonstrates:

proc format cntlout=temp;
  value test
    low-1=23
    2-5=45
    6-high=99;
run;

The dataset temp will show the output.

Astounding
PROC Star

Here are changes to make, for this to be suitable for creating a format:

 

data range;
input start end label $8.;

if label='Low' then HLO='L';

else if label='High' then HLO='H';

fmtname='Range';
cards;
-999999 1 Low
2 3 Medium
4 999999 High
;

 

Then you can create a format using:

 

proc format cntlin=range;

run;

 

And you can use the format when processing HAVE, by adding:

 

format num range.;

 

A few notes:

 

  • The variable names have been changed.  START, END, LABEL, and FMTNAME are required names.
  • Note that you have gaps here, for non-integer values.
  • When HLO="L", that tells PROC FORMAT to ignore the START value, and consider "Low" to be the start of the range.
  • Similarly, when HLO="H", that tells PROC FORMAT to ignore the END value, and consider "High" to be end of the range.
  • The name of the format (range.) comes from the FMTNAME variable, not from the name of the CNTLIN= data set.

 

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!

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
  • 2 replies
  • 2609 views
  • 0 likes
  • 3 in conversation