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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3184 views
  • 0 likes
  • 4 in conversation