Hi,
I have a dataset and i've saved the variables of it into two macro variables &gIS and &gSHOULD, i want to add two new columns to this dataset, summing over all the variables in &gIS and &gSHOULD. I wrote the following code but nothing happened the want i got is the same as have
DATA libl.want;
SET libl.have;
keep &gIS &gSHOULD;
sumIS=sum(of &gIS); /*In the hope that sumIS is the sum of all the variables in &gIS for all the observations. */
sumSHOULD=sum(of &gSHOULD);
RUN;
Can someone help me correct my code? Thanks very much.
BR Dingdang
What does &GLS look like? Using sum( of &gls) the sum function expects to see a variable list such as X1-x5 or X: If &GLS is a list of variables with spaces then the syntax is incorrect. If &gls is a list of variable or values then they should be comma delimited.
Can you provide example have and want datasets, as well as the code you are using to create the macro variables?
hi Arthur,
thanks for the quick response. Here is the code that i used for creating the two macro variables look like this:
proc sql;
select Feld
into :gIS separated by ' '
from informappe
where ...; /*here i omitted the conditions */
select Feld
into :gSHOULD separated by ' '
from informappe
where...;
quit;
the two macro variables have the same number of variables saved, like 40.
and then i have a big dataset have, which contains all the variables, including all variables from gIS and gSHOULD. I would like to create a new dataset want, with all the variables in gIS and gSHOULD from have, and then add two new variables sumIS and sumSHOULD to it, which contains just the sum of the variables in gIS and the sum of variables in gSHOULD.
for example var1-var40 are included in gIS and var41-var80 are included in gSHOULD. If I just select these variables from have, one observation looks like:
var1 var2 var3 var4....var40 var41 var42...var80
1 1 1 1 1 2 2 2
then the sumIS and sumSHOULD for the same observation is 40 and 80. and want looks like:
var1 var2 var3 var4....var40 var41 var42...var80 sumIS sumSHOULD
1 1 1 1 1 2 2 2 40 80
I hope i made myself clear this time.
BR Dingdang
What does &GLS look like? Using sum( of &gls) the sum function expects to see a variable list such as X1-x5 or X: If &GLS is a list of variables with spaces then the syntax is incorrect. If &gls is a list of variable or values then they should be comma delimited.
I read the use of sum function again and corrected the macro variables to comma delimited and then used sum(&gIS) and then it worked!! best thanks!!
Hi,
Do you get any warning or error messages? Perhaps post your log too.
Regards,
Amir.
You are not keeping the new summed variables.
keep &gIS &gSHOULD sumIS sumSHOULD;
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.
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.