01-28-2017 04:40 AM
I have written the code to import the data from excel into the WORK libraray. Then looping trough each observation , i'm calling from the required macro. Thus passing values from excel cells to a SAS macro.
PROC IMPORT OUT= WORK.EXCELTABLE DATAFILE= "C:\file.xlsx" DBMS=xlsx REPLACE; SHEET="auto"; GETNAMES=YES; RUN; data want; set EXCELTABLE; array COL1 COL2 COL3 ; do over COL1; %<macro name>(COL1, COL2, COL3); end; drop COL1; run;
-Hope it helps.
01-28-2017 04:58 AM
Looks like the typical misunderstanding of the macro processor. The macro is executed while the data step is being compiled, so it never has access to the values of datastep variables, only to their names as supplied as macro parameters.
To verify this, post the macro code.
01-28-2017 05:02 AM
@ankit___gupta you missd a step in your answer:
where is the macro definition and execution (doesn't matter what name you gave to it).
The proc import itself doesn't create macro variables.
the missed step, in between the import and the step to use is should be like:
set have; /* dataset created by import */
call symput('macro_var1', col1) ; /* when col1 is char */
call symput(macro_var2', left(col2)); /* when col2 is numeric */
then to use the macro variables:
col1 = symget('macro_var1');
/* or */
col2 = ¯o_var2;
/* both metthods are good either fo char or for numeric variables */
01-28-2017 08:34 AM
Hi, I am new to SAS. I need to pass two numeric values from excel cells to a SAS macro. But I have no idea, how to start. Right now, I am a lost ship in an ocean. Can anyone please help.
Save your spreadsheet to a csv file. This makes the transfer more controllable.
Read the csv data into SAS with a data step. Don't use proc import, as you want reliable, repeatable results.
In a data _null_ step, use the imported dataset, use firstobs= and obs= to locate the correct row/observation (if there's more than one), and use call symput() to create the macro variables.
01-30-2017 04:35 AM
Out of interest, why do you have two data elements in a spreadsheet? What is the process you are trying to do?
Personally, without any further information I would drop the spreadsheet totally and just have two lines at the start of the code:
Thats the only bit which needs changing then. Save all the faffing about.