Hello,
Right now, I have a data-set that looks like something along the following(lets call this data-set A):
| var1 | var2 |
| x | 2 |
| x | 5 |
| a | 7 |
| a | 2 |
| x | 7 |
| b | 8 |
What i am trying to do, is loop through var2 and export different datasets based on the value of var2. So in this example, i would create four data-sets, each out corresponding to the unique amount of values in var2(var2 is numeric). Right now, i grab the unique amount of values from a different data-set(lets call it B) and put them into a list with this code:
proc sql; select var2 into :list separated by ' ' from B; quit;From there I am trying to run the following code to create the data-sets.
%macro splitting;
%do i=1 %to %sysfunc(countw(&list.));
%let block&i. = %scan(&list., &i.,%str());
%put block&i.
proc sql;
create table table&i. as
select *
from A
where var2 contains &block&i.;
quit;
%end;
%mend splitting; I could, go through and do many different if-then statements, but i would rather not considering how many different data-sets I need to create. Can someone shed some light on the situation. Thanks.
ok, sounds good. I guess why I am trying to do this is because I am trying to stack multiple occurrences of the same variable in the same by-group that i need to make the "ID" when i transpose, and then append the data-sets together I will probably post another question based on this, than rather looping through macros. Please take a look.
https://communities.sas.com/t5/SAS-Programming/Transposing-and-Stacking/m-p/497899
Link to new questions.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.