11-29-2016 11:54 AM
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
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:
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.
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?
11-29-2016 12:17 PM
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".