Hi Everyone
I am trying to rename some values in a data step using a simple "if then" statement. When I try to do this using the values in 'DispositionType' below, I cannot get it to execute the "then" part of it. It just leaves the values as is. I have increased the length of 'DispositionType' to 50 characters to accommodate the new length of the values to no avail.
I have other "if thens" below that are executing fine, so I don't know what is wrong with this one.
Any ideas on this would be appreciated.
Paul
data s8StackedBarChart2 (rename=(tprYear=Year));
length County $ 25 tprYear 3 AgeRange $ 30 DispositionType $ 50
CohortYearTotal 5 CohortYearTotalAge 5 DistributiveNumber 5 DistributivePercent 5;
merge s8StackedBarCounty s8StackedBarCountyAA
s8StackedBarNys s8StackedBarNysAA
s8StackedBarNyc s8StackedBarNycAA
s8StackedBarRos s8StackedBarRosAA;
by County tprYear AgeRange DispositionType;
if DispositionType="Wit" then DispositionType="Withdrawn";
if DispositionType="Dis" then DispositionType="Dismissed";
if DispositionType="Sus" then DispositionType="Suspended Judgement";
if DispositionType="Par" then DispositionType="Parent's rights terminated";
if DispositionType="Oth" then DispositionType="Other";
if DispositionType="Pen" then DispositionType="Pending disposition";
if County="NewYork" then County="New York (Manhattan)";
if County="Kings" then County="Kings (Brooklyn)";
if County="Richmond" then County="Richmond (Staten Island)";
if AgeRange="0 to 3" then AgeRange="1 - 0 to 3";
if AgeRange="4 to 6" then AgeRange="2 - 4 to 6";
if AgeRange="7 to 9" then AgeRange="3 - 7 to 9";
if AgeRange="10 to 12" then AgeRange="4 - 10 to 12";
if AgeRange="13 to 15" then AgeRange="5 - 13 to 15";
if AgeRange="16 to 17" then AgeRange="6 - 16 to 17";
if AgeRange="All Ages" then AgeRange="7 - All Ages";
if AgeRange="Invalid Age" then AgeRange="8 - Invalid Age";
if Ground="All Locations" then Ground="All";
if AgeRange ne "8 - Invalid Age";
drop cnty_name Ground;
run;
Paul,
My guess is that you have a format assigned to DispositionType. Add the following statement, right under your length statement, and let us know if that corrects the problem:
format DispositionType $50.;
Paul,
My guess is that you have a format assigned to DispositionType. Add the following statement, right under your length statement, and let us know if that corrects the problem:
format DispositionType $50.;
If Art's suggestion does the trick, great. If not, here are a couple of possibilities.
DispositionType is not left-hand justified. Check that using:
if left(DispositionType)="Wit" then ...
Or, somehow the data entry process added unprintable characters such as a line feed at the end of DispositionType. Check that using:
if DispositionType =: "Wit" then ...
Good luck.
Hi Astounding
The unprintable characters is something I have wondered about in other situations actually. So the above will help with other variables we use here. Thanks.
Paul
Hi Art
That worked fine, thanks a lot.
I don't know why there would be a special format assigned to this variable, as I just copied it from another program with a similar variable and that worked fine.
Paul
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.