BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9

i have a stored process which gets id's

it looks like 17,18,19 for example

now what i want to do here is to append them all to the same dataset but with different variable names (A_17, A_18 , B_17, B_18 )

but at this point it already fails to read my do while statement

any help?

%macro CreateGraphData;
%let i = 0;
%do %while (scan(&curve_id,&i,',') NE '');
current_id = scan(&curve_id,&i,',');

data wacom_&i;
set RF300l3.wacom_main;
where curve_id = current_id;
run;

data wacom_&i (drop = A B);
set RF300l3.wacom_data;
where curve_id = current_id;

A_&i = A;

B_&i = B;
run;

if &i = 1 then do;
data all_data;
set wacom_&i;
run;
end;
else do;
proc append base=all_data data=wacom_&i force;run;
end;

%let i = &i + 1;
%end;
%mend;
%CreateGraphData;

4 REPLIES 4
Filipvdr
Pyrite | Level 9

ok, i almost there Smiley Happy

%macro GraphsData;
%let num=1;
   %let Curve=%scan(&curve_id,&num,'#');
   %do %while(&Curve ne);
      %put 1: &Curve;
   /* do action for this curve */
data wacom_#
  set RF300l3.wacom_main;
  where curve_id = &Curve;
run;

data wacom_#
  set RF300l3.wacom_data;
  where curve_id = &Curve;
run;
/*
if &i = 1 then do;
  data all_data;
   set wacom_&i;
  run;
end;
else do;
   proc append base=all_data data=wacom_&i force;run;
end;
*/
   /* scan for next round */
      %let num=%eval(&num+1);
      %let Curve=%scan(&curve_id,&num,'#');
   %end;
%mend;
%GraphsData;

Peter_C
Rhodochrosite | Level 12

you may not have noticed from examples that the macro language does not use quotes to indicate strings, but uses the %STR() function

So, not '#' but %STR(#) might help your %while()

kassimorra
Calcite | Level 5

This problem has been solved ?

Can you give an example ?

This isn´t hard, I just don´t get what you need.

Kassim

Tom
Super User Tom
Super User

Do you need the intermediate datasets with the numeric suffix?

If not then why not just use a data step?  Why do you need a macro?

data all_data;
  set RF300l3.wacom_main;
  where curve_id in (&Curve_id);
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3972 views
  • 0 likes
  • 4 in conversation