DATA Step, Macro, Functions and more

If then in data step

Accepted Solution Solved
Reply
Regular Contributor
Posts: 216
Accepted Solution

If then in data step

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;



Accepted Solutions
Solution
‎03-04-2013 11:29 AM
PROC Star
Posts: 7,468

Re: If then in data step

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.;

View solution in original post


All Replies
Solution
‎03-04-2013 11:29 AM
PROC Star
Posts: 7,468

Re: If then in data step

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.;

Super User
Posts: 5,498

Re: If then in data step

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.

Regular Contributor
Posts: 216

Re: If then in data step

Posted in reply to Astounding

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

Regular Contributor
Posts: 216

Re: If then in data step

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 216 views
  • 0 likes
  • 3 in conversation