BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AmrAd
Obsidian | Level 7

How can i identify in a data set a vairable with value and when found to let 3 follwing variable to be zero

Input data 

AcctsData_Q1_2017Data_Q2_2017Data_Q3_2017Data_Q4_2017Data_Q1_2018
Acc11 2 3
Acc2 1 23
Acc3    3
Acc4 11 3
Acc51  13

 

Requested output

 

AcctsData_Q1_2017Data_Q2_2017Data_Q3_2017Data_Q4_2017Data_Q1_2018
Acc110003
Acc2 1 00
Acc3    3
Acc4 1000
Acc510003

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    set have;
    array d data_q1_2017--data_q1_2018;
    do i=1 to dim(d);
        if d(i)=2 then do;
            if i+1 <= dim(d) then d(i+1)=0;
            if i+2 <= dim(d) then d(i+2)=0;
            if i+3 <= dim(d) then d(i+3)=0;
        end;
     end;
run;

If you want tested code, do not supply data as a screen capture, instead supply data as SAS data step code via these instructions: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    set have;
    array d data_q1_2017--data_q1_2018;
    do i=1 to dim(d);
        if d(i)=2 then do;
            if i+1 <= dim(d) then d(i+1)=0;
            if i+2 <= dim(d) then d(i+2)=0;
            if i+3 <= dim(d) then d(i+3)=0;
        end;
     end;
run;

If you want tested code, do not supply data as a screen capture, instead supply data as SAS data step code via these instructions: https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

--
Paige Miller
AmrAd
Obsidian | Level 7

It works 

 

Thanks a lot  🙂 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 945 views
  • 0 likes
  • 2 in conversation