|
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;
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;
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.
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.