BookmarkSubscribeRSS Feed
kisumsam
Quartz | Level 8

Hi there, I am reading the advanced exam prep guide and I got a few questions about proc formats. Hopefully some of you experts can help 🙂

 

Question 1

 

proc format;
value $route 'Route1' = 'Zone 1'
			 'Route2' - 'Route4' = 'Zone 2'
			 'Route5' - 'Route9' = 'Zone 3';
run;

data route;
format route $route.;
do i = 1 to 9;
route = 'Route' || compress(put(i, 2.0));
output;
end;
run;

This code is similar to what the prep guide has. It defines the formats mapping routes to different zones.

 

Currently, route2 to route4 are mapped to zone 2. Now, I'm gonna make some changes to the format and map route2 to route6 to zone 2:

 

proc format;
value $route 'Route1' = 'Zone 1'
			 'Route2' - 'Route6' = 'Zone 2'
			 'Route7' - 'Route9' = 'Zone 3';
run;

data route;
format route $route.;
do i = 1 to 9;
route = 'Route' || compress(put(i, 2.0));
output;
end;
run;

I still get the previous result:

 

i2.png

 

The format wasn't updated in SAS Studio. Is this a bug in SS? I tried the exact same code on SAS 9.4 and it worked.

 

Question 2

 

For zone 2, I changed the route as route2 to route12:

 

proc format;
value $route 'Route1' = 'Zone 1'
			 'Route2' - 'Route12' = 'Zone 2'
			 'Route13' - 'Route20' = 'Zone 3';
run;

I got this error message:

 

ERROR: Start is greater than end: -.

 

Could someone explain why? Does the range have to be within single digit?

 

 

2 REPLIES 2
Astounding
PROC Star

For question 2 ...

 

As character strings, "Route12" is less than "Route2".  The first five characters are identical, so the sixth character determines which is greater.  For this application, you could overcome this error by changing the second range:

 

'Route2'-'Route9', 'Route10'-'Route12' = 'Zone 2'

 

In other applications, it may not be so easy.  If you can control the data, it might help to use two-digit values, such as "Route01" instead of "Route1".

kisumsam
Quartz | Level 8

Thanks Astounding. That makes sense.

 

 

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
  • 2 replies
  • 921 views
  • 1 like
  • 2 in conversation