BookmarkSubscribeRSS Feed
SeekYourWay
Calcite | Level 5

Hi there,

this is my main program, which calls a SAS macro:

What I would like to do:

I need to populate the column "CT" in the Excel file with numeric numbers, which are essentially the value of the variable created in this SAS program. Please refer to the Excel file attached.

In worksheet "Test 2", you will see column CT, which already has values generated, but this is just test data. I would actually need to run this SAS program to be able to generate those numbers in column CT so that I can test and see if they match with what I already have in the Excel file. (The program needs to apply to every line of record in Excel, as you can tell).

Can the SAS program do that for me? If it doesn't output to Excel, that's fine,but the bottom line is I need to have column CT populated with numbers as a result of running above SAS code in SAS.

Is this possible? Is anyone able to assist me on this please? I'm new to SAS macro

Thanks very much

2 REPLIES 2
cwilson
Calcite | Level 5

Actually, I think you may be almost there.  It looks like all you have to do is output your work dataset to an excel file.  (Without some actual test data, I can't test for sure.)

I have added a few comments to your main code.

%Main Program; 

DATA test;

SET sasuser.test;

%A01_CPS_MH;

run ;  * I  recommend putting a run statement at the end of every data step, for clarity as well as to ensure execution if no other steps follow this one;

proc export data = test outfile ="C:\mySASfolder\myTestScoreResults.xlsx" DBMS=Excel2007 replace ;

run ;

%MEND scipp_2012_program; * this statement is outside of your data step ;

art297
Opal | Level 21

I agree with cwilson that your program appears to do what you want.  You don't really need to wrap the code in SAS macros, as you could have just included the code in a data step.

You also appear to have written scipp_2012_program as a SAS macro.  Again, not necessary, but it will still work that way.  However, if you are going to keep it as a macro, you have to change the first line and then call the macro.

Thus, stealing Carla's suggested code, you could use:

%macro scipp_2012_program;

  DATA test;

    SET sasuser.test;

    %A01_CPS_MH

  run ;

  proc export data = test outfile ="C:\mySASfolder\myTestScoreResults.xlsx" DBMS=Excel2007 replace ;

  run ;

%MEND scipp_2012_program;

%scipp_2012_program


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 909 views
  • 0 likes
  • 3 in conversation