BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I need someone to help me to explain the following process:

data sample:

flag num_a num_b
1 0 3
1 0 3
1 0 3
2 4 4

The task is to let num_a = num_b, then set num_b = 0, if flag equals 1.

expected result:

condition num_a num_b
1 3 0
1 3 0
1 3 0
2 4 4

I use a do-end loop to execute it, and coding like this:

if condition = 1 then do;
num_a = num_b;
num_b = 0;
end;

but it doesn't work
The first column is converted correctly, but the rest records are all set to 0. It look like it execue num_b=0 first then execute num_a=num_b;

the result ended up like this:

condition num_a num_b
1 3 0
1 0 0
1 0 0
2 4 4

Even I seperated the do loop steps it gets the same results:

revised code:

if condition = 1 then do;
num_a = num_b;
end;

if condition = 1 then do;
num_b = 0;
end;

Anyone can explain this to me?

Thanks,
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I suggest you run your code in a SAS DATA step, either using DATALINES; with an INPUT statement, or with a SET (from a previous SAS data member). Then add two statements, as shown below, around your code to generate diagnostics:

DATA _NULL_;
SET ;
PUTLOG ">BEFORE>" / _ALL_;
* your code goes here. ;
PUTLOG ">AFTER>" / _ALL_;
RUN;

With the additional DATA step processing diagnostics, I would expect you can see the processing results and reasoning with your own code. If the problem still exists, paste the entire SASLOG output into your post for the forum subscribers to respond with feedback. It's important that you share your exact DATA step code, using COPY and PASTE for accuracy and purpose.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hi dust,
The below mentioned code will give you the your desired result.
if flag = 1 then do;
num_a = num_b;
num_b = 0;
end;

By running the above code I am getting the below result
flag num_a num_b
1 3 0
1 3 0
1 3 0
2 4 4

not like what you have mentioned.once agin verify the above code,it will give you the your desired result.
deleted_user
Not applicable
Thanks all for your kindly response.
Sivas, that's eactly what troubles me. This piece of example is from an old program which had been runing for years. Someone found the problem with the output data recently, and I checked the process and identified the issue. It should work as you pointed out, but it didn't. Could that be possible it is caused by a SAS version problem? I have reasons to believe the code used to worked well. (Of course I can't be 100% sure.) An update SAS version in our unix environment last year may caused the problem. Again, just my guess.

Thanks again for your help
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
As was suggested, share your "executed" SAS code with additional diagnostics in a SASLOG (pasted in your post), otherwise feedback cannot be accurately provided, based on the lack of actual SAS output.

Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 656 views
  • 0 likes
  • 2 in conversation