BookmarkSubscribeRSS Feed
david27
Quartz | Level 8

Hello,

 

I am trying to create formats using a dataset.

I want to use Low and High as to accomodate extreme values.

But at the same time, i want dot(.) in its own category of missing.

 

Having issue doing that. I get error like this:

ERROR: Cannot mix missing and nonmissing values in the same range: 180-..

 

Please help.

data ctrl2;
	input start :$8. end  :$8.;
	datalines;
0 0
1 12
13 23
24 24
25 35
36 36
37 47
48 48
49 59
60 60
61 71
72 72
73 108
109 180
180 high
;
run;

data ctrl;
	set ctrl2 end=last;
	retain fmtname 'fmt_name_user' eexcl 'N';


	Label = strip(strip(Start)||"-"||strip(end));


	output;

	if last then
		do;
			hlo='O';
			label='Missing';
			output;
		end;
run;
proc format cntlin=ctrl;
run;

 

 

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16

Please try the below updated code, check the

 

if last statement

 

data ctrl2;
	input start :$8. end  :$8.;
	datalines;
0 0
1 12
13 23
24 24
25 35
36 36
37 47
48 48
49 59
60 60
61 71
72 72
73 108
109 180
180 high
;
run;

data ctrl;
	set ctrl2 end=last;
	retain fmtname 'fmt_name_user' eexcl 'N';


	Label = strip(strip(Start)||"-"||strip(end));


	output;

	if last then do;
			start='';
            end='';
			label='Missing';
			output;
		end;
run;

proc format cntlin=ctrl fmtlib;
run;
Thanks,
Jag
Astounding
PROC Star

It's a mistake to read in START and END as character variables.  Remove the $ from the INPUT statement, and make them numeric.

 

You can still create LABEL easily enough:

 

label = cats(start, '-', end);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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