Help using Base SAS procedures

Looking for help with what code is doing.

Accepted Solution Solved
Reply
Super Contributor
Posts: 398
Accepted Solution

Looking for help with what code is doing.

Hello,

I'm looking at a piece of code a previous program wrote and I'm stuck on what seems like a very simple piece of code but I can't seem to figure out what it is doing.

I have 2 tables with the same list of people ids from two separate years.  Each row can have up too 3 phone numbers for that person per year.  In this code it's merging the two tables by the person id and an array is created for the set of variables from each year.  My issue is what is happening in the do loop?  Is it just setting the first array equal to the second array?

data phone

    length pid id_a id_b phid1_a phid2_a phid3_a phid1_b phid2_b phid3_b 8 ;      

    merge

        line_1 (rename=(ID=ID_A PHID1=PHID1_A PHID2=PHID2_A PHID3=PHID3_A))

        line_2 (rename=(ID=ID_B PHID1=PHID1_B PHID2=PHID2_B PHID3=PHID3_B))

        ;

        by pid ;

        array phna {*} phytype_a phone_a ext_a listed_a ;

        array phnb {*} phytype_b phone_b ext_b listed_b ;

    do i = 1 to dim(phna) ;

        phna(i) = phnb(i) ;

    end ;  

run ;

Thank you for any help.


Accepted Solutions
Solution
‎11-11-2014 10:06 AM
Super User
Super User
Posts: 7,407

Re: Looking for help with what code is doing.

Yep, not sure what the question was exactly, but phna can be thought of as an alias to the listed variables and phnb to the others, so phyntype_b = phyntype_a, phone_b = phone_a.  I think they are trying to avoid a long list of this variable = that variable, though for four assignments its a bit pointless.

View solution in original post


All Replies
Solution
‎11-11-2014 10:06 AM
Super User
Super User
Posts: 7,407

Re: Looking for help with what code is doing.

Yep, not sure what the question was exactly, but phna can be thought of as an alias to the listed variables and phnb to the others, so phyntype_b = phyntype_a, phone_b = phone_a.  I think they are trying to avoid a long list of this variable = that variable, though for four assignments its a bit pointless.

Super Contributor
Posts: 305

Re: Looking for help with what code is doing.

Hello,

The value of each variable in the first array will be the value of the corresponding variable in the second array.

E.G. phytype_a will have the value of  phytype_b

Trusted Advisor
Posts: 1,204

Re: Looking for help with what code is doing.

Yes, I think it can be done without introducing rename and arrays as long as you put line_2 dataset after line_1 dataset in merge statement.

Super Contributor
Posts: 398

Re: Looking for help with what code is doing.

Hello,

Thank you everyone for your help.  I just wanted to make sure I was making sense of it before I proceeded.

stat@sas,  I have different values in of the rename fields, won't that only leave one version of the variables? pid is the only variable value that they will have in common.

Thanks again for clarifying the code for me.

Trusted Advisor
Posts: 1,204

Re: Looking for help with what code is doing.

Hi,

Yes, it will leave only one version of the variables. I was assuming that you just want to update phone and other variables based on latest information contained in line_2 dataset.

Super Contributor
Posts: 398

Re: Looking for help with what code is doing.

Hi stat,

I do but I have to keep the id values for reference later in the process by another co-worker.

Thank you so much for your help.

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 216 views
  • 6 likes
  • 4 in conversation