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

Hello,  i have 12 datasets that have data for each month of the year and I'd like to search for the data for 3 people within all data and produce a stacked dataset of all data at the end containing all data for these people in the year.

 

The data sets are labeled as such:  Data201910 , Data201911, Data201912, et. The last two digits represent the month

 

I need to pull data for person 1, 2, and 3. 

 

How would I make an array to do this quickly rather than querying each data set? 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @jmmedina25 

 

According to your description, array seems not to be the right solution, as array can loop through multiple variables but not datasets.

I believe you nee a macro to make this repetitive task.

 

I have written the below code. Please adapt the WHERE statement and test it.

 

Thank you

 


/*UNTESTED CODE*/
%macro _search;

	%do i=1 %to 9;
	
		data want&i;
			set Data20190&i;
			where ID in (1,2,3); /*to be adapted according to your variables*/	
		run;
	%end;
		
	%do i=10 %to 12;
		data want&i;
			set Data2019&i;
			where ID in (1,2,3); /*to be adapted according to your variables*/	
		run;		
	%end;
		
%mend;

%_search;

data want;
	set want:;
run;

View solution in original post

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @jmmedina25 

 

According to your description, array seems not to be the right solution, as array can loop through multiple variables but not datasets.

I believe you nee a macro to make this repetitive task.

 

I have written the below code. Please adapt the WHERE statement and test it.

 

Thank you

 


/*UNTESTED CODE*/
%macro _search;

	%do i=1 %to 9;
	
		data want&i;
			set Data20190&i;
			where ID in (1,2,3); /*to be adapted according to your variables*/	
		run;
	%end;
		
	%do i=10 %to 12;
		data want&i;
			set Data2019&i;
			where ID in (1,2,3); /*to be adapted according to your variables*/	
		run;		
	%end;
		
%mend;

%_search;

data want;
	set want:;
run;
novinosrin
Tourmaline | Level 20

Hi @jmmedina25  Since your datasets have an easy naming sequence, all you probably need is

 

data want;
set Data201901-Data201912;
where person in (1,2,3);
run;
jmmedina25
Obsidian | Level 7

This worked well and is simple, thank you!

 

ed_sas_member
Meteorite | Level 14

You're welcome Smiley Happy

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1401 views
  • 0 likes
  • 3 in conversation