BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I appreciate if anyone can help me with the logic as I am new to SAS.
I have a dataset where I had to compare the values of 12 columns against each other.
Scenario: I have Column1, Column2… Column12. The values in all the columns can only be either 1 or 0. I should compare 2 columns and make sure if the value is changing from 1 to 0. If yes, then I should make sure that it remains 0 for 5 more columns starting from second column. I am planning on having a new column with a flag to say ‘Yes’ if it meets the above criteria or else ‘No’.

Thanks in advance
Sarah
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
If I understand your question right, you want to see if your data have this pattern
1,0,0,0,0,0
and set another variable to 'Yes' if so and otherwise 'No'.

A simple IF-THEN construct would do it:

IF column1=1 & column2=0 & column3=0 & column4=0 & column5=0 & column6=0 THEN Flag='Yes';
ELSE Flag='No';
deleted_user
Not applicable
Sorry, I could explain well in my previous post. I will try to make you understand better with some examples.

My Dataset looks like below

Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 Col11 Col12 Col13 Col14
Prd1 wh1 1 0 0 0 0 0 1 0 0 0 0 0
Prd1 wh2 1 1 0 0 0 0 0 1 1 1 1 1
Prd1 wh3 0 0 0 0 0 1 0 0 0 0 0 0
Prd1 wh4 1 0 0 0 0 0 0 1 0 0 0 0

Row1: Col1 has Product1, Column2 has Warehouse1, Column3 through Column14 has values of 1’s and 0’s. Now, I have to do a check for column3 through column14. Now I have to test that if the value in Column 3=1 and Column 4 = 0 then values from Column 5 through Column 8 should be 0’s and at the same time if Column 9 =1 and Column 10 = 0 then values from Column 11 through Column 14 should be 0’s.
Row2: If Column 3= 1 and Column 4= 1 then there is no rule to be applied. But if in the same row if Column 5=0 then values from Column 6 through Column 9 should be 0’s. (I should see that they are 0’s for atleast 5 columns including Column )5
Note: I should only make sure that the values in the columns are 0’s only if there was a change in value between previous column from 1 to 0.
I hope it is clear now. Please let me know if you have any questions.

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
  • 2 replies
  • 701 views
  • 0 likes
  • 2 in conversation