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

Hi Guys,

 

I have a dataset which looks a bit like this - 

 

AccountNoAccounIDFistNameSecondNameAddress1Address2
11DavidSmith1 Any StAnytown
21Sharon Stevens12 Somewhere St Somewhere
22PeterStevens  
23SamuelStevens  
31Robert Brown44 Elsewhere StElsewhere
32Janice Black  
41SengaLafferty7 Overthere StOverthere
42JohnYoung  

 

So for each AccountNo, when AccountID = 1 all the data is present.

 

How do copy the data for AccountID = 1 into the blank fields for AcountID's > 1?

 

hope that makes sense,

 

best regards,

 

paul

1 ACCEPTED SOLUTION

Accepted Solutions
DanielSantos
Barite | Level 11

Hi.

 

Not tested, but if all data is always at AccountID = 1 and there is no duplicates by AccountNo, AccountID then this may work.

 

 

proc sql noprint;
     create table WANT as
     select a.*, b.Address1, b.Address2
     from HAVE (drop = Address1 Address2) as a left join
          HAVE (keep = AccountNo AccountID Address1 Address2) as b
     on a.AccountNo = b.AccountNo and b.AccountID = 1;
quit;

 

Hope it helps.

 

Daniel Santos @ www.cgd.pt

View solution in original post

4 REPLIES 4
ballardw
Super User

RETAIN allows you to keep values from one record to the next. So create temporary variables to hold them when assigned and assign as needed.

 

data want;
   set have;
   length laddress1 laddress2 $ 25; /*<= length should be same as the original address variables*/
   retain laddress1 laddress2;
   if not missing(address1) then laddress1=address1;
   if not missing(address2) then laddress2=address2;
   if  missing(address1) then address1=laddress1;
   if  missing(address2) then address2=laddress2;
   drop laddress1 laddress2;
run;
DanielSantos
Barite | Level 11

Hi.

 

Not tested, but if all data is always at AccountID = 1 and there is no duplicates by AccountNo, AccountID then this may work.

 

 

proc sql noprint;
     create table WANT as
     select a.*, b.Address1, b.Address2
     from HAVE (drop = Address1 Address2) as a left join
          HAVE (keep = AccountNo AccountID Address1 Address2) as b
     on a.AccountNo = b.AccountNo and b.AccountID = 1;
quit;

 

Hope it helps.

 

Daniel Santos @ www.cgd.pt

mkeintz
PROC Star
Consider:

Data want;
SET have;
P=1;
If cats(address1,address2)='' then set have (keep=address1 address2) point=p;
Run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
pandhandj
Obsidian | Level 7

thankyou to everyone who took the time to help me with this one.  Your efferts are very much appreciated.

 

thanks,

 

paul

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 4 replies
  • 964 views
  • 1 like
  • 4 in conversation