Help using Base SAS procedures

PC SAS Logic

Reply
N/A
Posts: 0

PC SAS Logic

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
Trusted Advisor
Posts: 2,113

Re: PC SAS Logic

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';
N/A
Posts: 0

Re: PC SAS Logic

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.
Ask a Question
Discussion stats
  • 2 replies
  • 123 views
  • 0 likes
  • 2 in conversation