Dear,
I have two questions in my pgm below. First, the data step 'one' is giving me errors when i insert in the macro. Second, in the data step three, depends on how many "treat" variable values i need calculate character variables for the "value" variables. Please suggest. Thank you.
output needed:
a1 b1 c1
100 200 300
%macro want;
data one;
input treat $ value;
cards;
a1 100
b1 200
c1 300
;
run;
proc sql noprint;
select strip(put(count (distinct treat), best.)) into: cnt from one
order by treat;
quit;
%put &cnt.;
proc transpose data=one out=two prefix=T;
var value;
run;
%do i=1 %to &cnt.;
data three;
set two;
n&i.=compress(put(T&i.,5.));
a1=n1;
b1=n2;
c1=n3;
run;
%end;
run;
%mend;
%want;
cards or datalines are not allowed in a macro. The ERROR message you get when trying to execute your macro is very clear:
ERROR: The macro WANT generated CARDS (data lines) for the DATA step, which could cause incorrect results. The DATA step and the
macro will stop executing.
NOTE: The data set WORK.ONE has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
ERROR: The macro WANT will stop executing.
@knveraraju91 wrote:
Dear,
I have two questions in my pgm below. First, the data step 'one' is giving me errors when i insert in the macro. Second, in the data step three, depends on how many "treat" variable values i need calculate character variables for the "value" variables. Please suggest. Thank you.
output needed:
a1 b1 c1
100 200 300
The output of proc transpose looks very much like the required output, only thing to do is dropping the variable _name_. Why do you think that you need macro code at all?
EDIT: Wait, i see you need the values of "treat" as names for the transposed columns. Try:
proc transpose data=one out=two(drop=_name_);
var value;
id treat;
run;
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.