BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Hi,

I have to concat the information given in different cell with same ID and Date.

data Have;
input ID Dt mmddyy10. Activity:$30. Act_freq:$30.;
cards;
123	12/19/2010 Walking Daily
123	12/19/2010 NormalWalking Daily
run;

For instance: Have:

ID  Date Activity Act_freq
123 19-12-2010 Walking Daily
123 19-12-2010 NormalWalking Daily

 

Want:

ID  Date Activity Act_freq
123 19-12-2010 Walking, NormalWalking Daily, Daily

 

Kindly suggest a code to get this format.

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data Have;
input ID Dt mmddyy10. Activity:$30. Act_freq:$30.;
format dt mmddyy10.;
cards;
123	12/19/2010 Walking Daily
123	12/19/2010 NormalWalking Daily
run;

data want ;
  do until(last.dt) ;
    set have ;
    by id dt ;
    length _activity _Act_freq  $100 ;
    _activity=catx(', ', _activity, activity) ;
    _Act_freq=catx(', ',_Act_freq, Act_freq) ;
  end ;
  drop activity Act_freq;
  rename _Act_freq=Act_freq _activity=activity ;
run ;

proc print noobs ; run ;

RESULT:

ID Dt activity Act_freq
123 12/19/2010 Walking, NormalWalking Daily, Daily

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
data Have;
input ID Dt mmddyy10. Activity:$30. Act_freq:$30.;
format dt mmddyy10.;
cards;
123	12/19/2010 Walking Daily
123	12/19/2010 NormalWalking Daily
run;

data want ;
  do until(last.dt) ;
    set have ;
    by id dt ;
    length _activity _Act_freq  $100 ;
    _activity=catx(', ', _activity, activity) ;
    _Act_freq=catx(', ',_Act_freq, Act_freq) ;
  end ;
  drop activity Act_freq;
  rename _Act_freq=Act_freq _activity=activity ;
run ;

proc print noobs ; run ;

RESULT:

ID Dt activity Act_freq
123 12/19/2010 Walking, NormalWalking Daily, Daily
PaigeMiller
Diamond | Level 26

I don't really know what you intend to do with this data, but I think anything you could possibly do with this data in SAS would be easier to do if you left the data in the original format.

--
Paige Miller
ballardw
Super User

What is the maximum number of activity or frequency values that could ever be expected to end up in single cell?

You kind of need to know that to allocate a variable long enough to hold that many values plus space for commas and spaces between the values.

 

Also, just what do you expect to do with that data structure that you can't do with the current one?

(It is sort of amazing how many times I get no answer to this question for basically the same data mangling)

PaigeMiller
Diamond | Level 26

@ballardw wrote:

Also, just what do you expect to do with that data structure that you can't do with the current one?

(It is sort of amazing how many times I get no answer to this question for basically the same data mangling)


I feel the same way.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 886 views
  • 1 like
  • 4 in conversation