BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pavank
Quartz | Level 8
  • US_CITIES from , create a format POP_CAT and write a PROC PRINT procedure to obtain the following output :

CITY

POPULATION

Anchorage

Medium

San Antonio

Huge

San Juan

Medium

Minneapolis

Medium

Dallas

Huge

Miami

Medium

Baltimore

Big

Detroit

Big

New York

Huge

Phoenix

Huge

Denver

Big

El Paso

Big

Los Angeles

Huge

Sacramento

Medium

San Francisco

Big

Las Vegas

Big

 

 

 

Note : a city population less than 500.000 is considered medium, between 500.000 and one million is considered big, and equal or more than one million is considered huge

 

 

data US_Cities;
input Timezone $8. State $13. City $15.  Population ;
datalines;
Alaska	   Alaska	    Anchorage	      291826
Atlantic   Puerto Rico	San Antonio	     1327407
Atlantic   Puerto Rico	San Juan	      395326
Central	   Minnesota	Minneapolis	      382578
Central	   Texas	    Dallas	         1197816
Eastern    Florida	    Miami	          399457
Eastern	   Maryland  	Baltimore	      620961
Eastern	   Michigan	    Detroit	          713777
Eastern    New York	    New York	     8175133
Mountain   Arizona	    Phoenix	         1445631
Mountain   Colorado	    Denver	          600158
Mountain   Texas	    El Paso	          649121
Pacific	   California	Los Angeles	     3792621
Pacific	   California	Sacramento	      466488
Pacific	   California	San Francisco     805235
Pacific	   Nevada	    Las Vegas	      583756
;
run;






proc format ;
value $pop_cat  medium=>500.000
                big=between 500.000 to 1 million
                huge=> 1 million;
run;                


proc print data= US_Cities NOOBS ;
VAR TIMEZONE STATE  CITY POPULATION ;
BY CITY ;
SUM POPULATION;
RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Sajid01
Meteorite | Level 14

Hello @pavank 
I have corrected / updated your code to get the output you want.

data US_Cities;
	input Timezone $8. @11 State  & $13. @23 City $15. @41 Population;
	datalines;
Alaska	   Alaska       Anchorage	      291826
Atlantic   Puerto Rico  San Antonio	     1327407
Atlantic   Puerto Rico  San Juan	      395326
Central	   Minnesota	Minneapolis	      382578
Central	   Texas	    Dallas	         1197816
Eastern    Florida	    Miami	          399457
Eastern	   Maryland  	Baltimore	      620961
Eastern	   Michigan	    Detroit	          713777
Eastern    New York	    New York	     8175133
Mountain   Arizona	    Phoenix	         1445631
Mountain   Colorado	    Denver	          600158
Mountain   Texas	    El Paso	          649121
Pacific	   California	Los Angeles	     3792621
Pacific	   California	Sacramento	      466488
Pacific	   California	San Francisco     805235
Pacific	   Nevada	    Las Vegas	      583756
;
run;

proc format;
	value pop_cat 
	low -< 500000='Medium'
	500000 -< 1000000='Big' 
		1000000 -high='Huge';
run;

proc print data=US_Cities NOOBS;
	VAR CITY POPULATION;
	Format population pop_cat.;
RUN;

 

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Maxim 2: Read the Log, especially that of the PROC FORMAT step.

Then apply Maxim 1: Read the Documentation, and study PROC FORMAT , particularly the VALUE statement, to see where you went wrong.

Additional hint: you want to format a numeric variable, so you want a numeric format.

Sajid01
Meteorite | Level 14

Hello @pavank 
I have corrected / updated your code to get the output you want.

data US_Cities;
	input Timezone $8. @11 State  & $13. @23 City $15. @41 Population;
	datalines;
Alaska	   Alaska       Anchorage	      291826
Atlantic   Puerto Rico  San Antonio	     1327407
Atlantic   Puerto Rico  San Juan	      395326
Central	   Minnesota	Minneapolis	      382578
Central	   Texas	    Dallas	         1197816
Eastern    Florida	    Miami	          399457
Eastern	   Maryland  	Baltimore	      620961
Eastern	   Michigan	    Detroit	          713777
Eastern    New York	    New York	     8175133
Mountain   Arizona	    Phoenix	         1445631
Mountain   Colorado	    Denver	          600158
Mountain   Texas	    El Paso	          649121
Pacific	   California	Los Angeles	     3792621
Pacific	   California	Sacramento	      466488
Pacific	   California	San Francisco     805235
Pacific	   Nevada	    Las Vegas	      583756
;
run;

proc format;
	value pop_cat 
	low -< 500000='Medium'
	500000 -< 1000000='Big' 
		1000000 -high='Huge';
run;

proc print data=US_Cities NOOBS;
	VAR CITY POPULATION;
	Format population pop_cat.;
RUN;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2177 views
  • 0 likes
  • 3 in conversation