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

Let's say I have a two columns, 1 with a bunch of names, and another with a bunch of dates:

 

 

 

data out;
set in;
%let d=400;

array name{&d};
array indate{&d};
h=1;
do i=1 to &d;
   if substr(name{i},1,4) in ("asdf", "jklo") then do;
       eh&h=indate{i}
       h=h+1;
   end;
end;
run;

This code is able to count the number of occurnaces of names "asdf" and "jklo" and set them for each observation as "h".

 

However, when I try to create the variable "eh&h" with &h to represent the h'th occurance of the names, it doesn't work.

 

How can I make it so the variable names created to set as indate contains the value of h for a given observation?

 

I tried even to create an array using the dimension of maximum number of h's in the dataset, but that didn't work either (and may have been the wrong idae). So i come here to see if there's something i'm just missing.

 

Thanks ahead of time.

1 ACCEPTED SOLUTION

Accepted Solutions
chrisengel
Obsidian | Level 7

Solved it myself, here's the code:

 

data out;
set in;
%let d=400;
%let e=50; *Max dimensions for the number of h's;

array name{&d};
array indate{&d};
array eh{&e};
h=1;
do i=1 to &d;
   if substr(name{i},1,4) in ("asdf", "jklo") then do;
       eh{h}=indate{i}
       h=h+1;
   end;
end;
run;

View solution in original post

1 REPLY 1
chrisengel
Obsidian | Level 7

Solved it myself, here's the code:

 

data out;
set in;
%let d=400;
%let e=50; *Max dimensions for the number of h's;

array name{&d};
array indate{&d};
array eh{&e};
h=1;
do i=1 to &d;
   if substr(name{i},1,4) in ("asdf", "jklo") then do;
       eh{h}=indate{i}
       h=h+1;
   end;
end;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 647 views
  • 0 likes
  • 1 in conversation