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

Hi All: 

 

I have data that is like this:

ColumnAColumnB
@1email1232;0829
@2email1232;0829;0938
@1email0938;48294;2938
@4email0829;0938;0384

 

my goal is to get this: 

Basically the count of column B each number before the ; - how many times they showed up 

ColumnAColumnB
12322
08293
09383
482941
29381
03841
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input (ColumnA	ColumnB	) (:$20.);
cards4;
@1email	1232;0829
@2email	1232;0829;0938
@1email	0938;48294;2938
@4email	0829;0938;0384
;;;;

data temp;
set have;
do _n_=1 to countw(columnb,';');
 v=scan(columnb,_n_,';');
 output;
end;
keep v;
run;

proc freq data=temp ;
tables v/out=want(keep=v count);
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

data have;
input (ColumnA	ColumnB	) (:$20.);
cards4;
@1email	1232;0829
@2email	1232;0829;0938
@1email	0938;48294;2938
@4email	0829;0938;0384
;;;;

data temp;
set have;
do _n_=1 to countw(columnb,';');
 v=scan(columnb,_n_,';');
 output;
end;
keep v;
run;

proc freq data=temp ;
tables v/out=want(keep=v count);
run;
PaigeMiller
Diamond | Level 26

It would help if your outputs corresponded to the inputs. Or if you explained how the outputs are derived from the inputs, that would also help.

 

As it is, I don't see how your fourth line of input corresponds to anything in the output, and then there are two extra lines of output that don't correspond to the inputs.

 

So please explain, and provide examples of input data and desired output consistent with the explanation.

 
--
Paige Miller
novinosrin
Tourmaline | Level 20

Something fancy



data have;
input (ColumnA	ColumnB	) (:$20.);
cards4;
@1email	1232;0829
@2email	1232;0829;0938
@1email	0938;48294;2938
@4email	0829;0938;0384
;;;;

data _null_;
 if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("v") ;
   h.definedata ("v","count") ;
   h.definedone () ;
 end;
set have end=z;
do _n_=1 to countw(columnb,';');
 v=scan(columnb,_n_,';');
 if  h.find() ne 0 then count=1;
 else count=sum(count,1);
 h.replace();
end;
if z;
h.output(dataset:'want');
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 584 views
  • 1 like
  • 3 in conversation