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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Loko
Barite | Level 11

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

stat_sas
Ammonite | Level 13

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.

jerry898969
Pyrite | Level 9

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.

stat_sas
Ammonite | Level 13

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.

jerry898969
Pyrite | Level 9

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.

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
  • 6 replies
  • 816 views
  • 6 likes
  • 4 in conversation