BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello,
Herewith I have given my code and the error message.
Please let me know where I go wrong. I'm in immediate need.
Thanks in advance.

%macro sumcov (n1=, n2=);
%let n1=&n1;
%let n2=&n2;
texpos=sum(of expos&n1 - expos&n2);
-
-
-%mend sumcov;

%sumcov(n1=0,n2=2);

The message is as follows:

symbolgen:macro variable N1 resolves to 0
symbolgen: macro variable N2 resolves to 2
-
-
-
-
note: Variable expos0 is uninitialized
note: Variable expos1 is uninitialized
note: Variable expos2 is uninitialized

-------------
Please help me...
7 REPLIES 7
art297
Opal | Level 21
Your messages are telling you that you are trying to use macro variables with the sum function (namely, &expos0, &expos1 and &expos2), but have never assigned values to those variables.

You also should have received an error message regarding your statement texpos=, as that would only be valid within a data step.

Art
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
More accurately, your either have an incomplete SAS DATA step in your program or you have not shared all of your SAS program code in your post -- that is important when requesting assistance or guidance with this forum.

As well, learning your SAS version, whether SAS is running local or remote (server) sometimes helps, and OS platform environment information. Lastly, in this case, knowing if this is a new SAS program you are coding or if you are making changes to an existing program is also quite useful.

So, at this point, you have SAS variables revealed in the NOTE messages which are telling you that the variables are "uninitialized", meaning that they were not referenced in the SAS DATA step. A part of each variable is resolved using macro variables, which is a contributing factor.

You will need to determine how those SAS variables are to be used in your program, if at all, and then correct your SAS DATA step code accordingly.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

variable uninitialized site:sas.com

data step programming site:sas.com
deleted_user
Not applicable
Hi all,

Thank u very much for your reply.

In my code, i have my array declaration in the data step and I have initialised values also like below.. this is done before the calling of the macro function.

array expos(0:32) x0 - x32;

where x0 till x32 are already read data values.

My doubt here is, should I have to declare this array inside the macro? or should I have to declare this array variable as macro variables in order to use it inside macro? and also how to do it.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You will need to read up on using the ARRAY statement -- your use of a variable suffix only in the declaration is incorrect. For the SAS variables within the array, SAS expects the full-name to be defined. You do not need to code the ARRAY inside the macro, as long as the ARRAY is declared within the DATA step itself.

Therefore, what is the purpose of these SAS DATA step variables, given your initial question:

note: Variable expos0 is uninitialized
note: Variable expos1 is uninitialized
note: Variable expos2 is uninitialized

Lastly, you will see the most useful diagnostic output from your SAS program with all code revealed by having this statement at the beginning:

OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT /* MLOGIC */;

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Cynthia_sas
SAS Super FREQ
Hi:

As Scott recommended, you need to read up on how ARRAYs work in SAS and about ARRAY referencing. And, perhaps understand a bit more about how the Macro facility works. This is a good introduction on using ARRAYs:
http://support.sas.com/rnd/papers/sgf07/arrays1780.pdf
And this is a good introdution to the SAS Macro facility:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

You are not actually getting an error message on a MACRO variable, you are getting a NOTE on an unitialized DATA step variable. The message you listed:
[pre]
note: Variable expos0 is uninitialized
note: Variable expos1 is uninitialized
note: Variable expos2 is uninitialized
[/pre]

is put into the log because the macro variable references in your macro program resolved to the wrong DATA step variables.

Remember that the invocation of %SUMCOV is ONLY, ONLY, ONLY going to generate one single assignment statement for TEXPOS -- the macro program is not doing anything else except building this ONE statement every time you invoke the %SUMCOV macro program. Then, that statement, in the context of a DATA step program will be sent to the SAS compiler and then the statement (without ANY macro references) will go forward to be executed.

So, think about the code you want to generate -- did you start with working code? The macro facility is going to generate ONE single statement for you:
TEXPOS=sum(of resolved reference1 - resolved reference2 );


This is the array statement you showed:
[pre]
array expos(0:32) x0 - x32;
[/pre]

Which one of these statements (with resolved references) do you want/need to generate for THIS single invocation of %SUMCOV:
%sumcov(n1=0,n2=2);
[pre]
texpos=sum(of expos0- expos2);

OR

texpos=sum(of x0-x2);
[/pre]

Since your ARRAY is referencing variables X0-X32 -- there ARE not any EXPOS0-EXPOSn variables in your dataset to be used with the SUM function -- which is the cause of the "Variable xxx is not initialized" note. So, you need to explain a bit more about the processing you hope to accomplish with your macro program. If possible, post ALL of the code and explain what you need to do with your SUM statement. And also explain whether you need to generate multiple values for TEXPOS or whether you just need to generate 1 value for TEXPOS.

If you are referencing a variable as an ARRAY member, such as the one shown above in a DO loop, then you might have code like this to reference your variables in an array -- such as when you want to create a total from all the array members:
[pre]
array expos(0:32) x0 - x32;
do i = 0 to 32;
total = sum(total , expos(i));
end;
[/pre]

Note the use of the ARRAY reference to expos(i) where I is the index for the array name EXPOS. So, when i = 0, then EXPOS(I) is actually referencing the variable X0. Remember that SAS ARRAYs are not physical data constructs -- they provide a simple way to reference multiple variables as though they were members of an array. This means that the variables do NOT necessarily need to be numbered variables. These are all valid ways to declare ARRAYs for referencing:
[pre]
array tvshow $ tv1 tv2 tv3 tv4;
array henson $ sesame fraggle muppet otter;
array allnum _numeric_;
array allchar $ _character_;
array slprf sales discount commission profit;
array numvar var1 var5 var15 var20;
array nv var:;
array other var1-var20;
[/pre]

You also questioned the correct placement for the ARRAY statement itself -- whether it should go into the macro program or into the DATA step. Given what we know so far, the ARRAY statement should not be placed INSIDE of the %MACRO/%MEND definition. That's because your ARRAY statement -- a DATA step statement -- is a compile time statement and only needs to be put into the DATA step program 1 time.

Consider the following program. It uses SASHELP.CLASS and declares 2 arrays -- one for all the character variables (NAME and SEX) and another for all the numeric variables (AGE, HEIGHT and WEIGHT). The only purpose of the program is to show that the array reference is really only pointing to variable in the Program Data Vector. It also illustrates 2 different ways to use the SUM function -- one using array references (to calculate the TOT variable and the other way uses the variable names. So when I=3, ALLNUM(I) is pointing to the variable WEIGHT and when I=2, ALLNUM(I) is pointing to the variable HEIGHT, etc.

cynthia

[pre]
5710 data makearr;
5711 set sashelp.class(obs=2);
5712 array allnum _numeric_;
5713 array allchar $ _character_;
5714 putlog '***** ***** ***** ' _n_= name= sex= age= height= weight=;
5715 putlog '*** entering DO loop for ALLCHAR Array ***';
5716 do i = 1 to dim(allchar);
5717 putlog i= allchar(i)=;
5718 end;
5719 putlog '*** entering DO loop for ALLNUM Array ***';
5720 do i = 1 to dim(allnum);
5721 tot = sum(tot,allnum(i));
5722 putlog i= allnum(i)= tot=;
5723 end;
5724 tot2 = sum (age, height, weight);
5725 tot3 = sum (of allnum(*));
5726 putlog '*** outside DO loop for ALLNUM ' tot2= tot3=;
5727 putlog ' ';
5728 run;

***** ***** ***** _N_=1 Name=Alfred Sex=M Age=14 Height=69 Weight=112.5
*** entering DO loop for ALLCHAR Array ***
i=1 Name=Alfred
i=2 Sex=M
*** entering DO loop for ALLNUM Array ***
i=1 Age=14 tot=14
i=2 Height=69 tot=83
i=3 Weight=112.5 tot=195.5
*** outside DO loop for ALLNUM tot2=195.5 tot3=195.5

***** ***** ***** _N_=2 Name=Alice Sex=F Age=13 Height=56.5 Weight=84
*** entering DO loop for ALLCHAR Array ***
i=1 Name=Alice
i=2 Sex=F
*** entering DO loop for ALLNUM Array ***
i=1 Age=13 tot=13
i=2 Height=56.5 tot=69.5
i=3 Weight=84 tot=153.5
*** outside DO loop for ALLNUM tot2=153.5 tot3=153.5
NOTE: There were 2 observations read from the data set SASHELP.CLASS.
[/pre]
deleted_user
Not applicable
Hi all,

Thank you very much. I got my program executed and now it is giving out results.

-A.K
sivaji
Fluorite | Level 6
texpos=sum(of &&expos&n1. - &&expos&n2.);

this may work...

S

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
  • 7 replies
  • 2783 views
  • 0 likes
  • 5 in conversation