BookmarkSubscribeRSS Feed
Grandhi4
Calcite | Level 5

How to develop a code in SAS Macros like a XL (formulas) can i get any sample code or example ?

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  An Excel formula is different from a SAS Macro program. For example, if you build a formula in Excel for a new column (D) based on multiplying the value in column B by the value in column C, you might have a formula like:

=sum(b2*c2)

and then you might copy that formula down the entire column D (see excel formula part of the screenshot) in order to populate the whole column with values.

  But in SAS, if column B represented VALUE and column C represented DISCOUNT and column D represented DISCVAL (final discount value), then you would calculate DISCVAL this way (in a longer program shown in screenshot):

DISCVAL=VALUE * DISCOUNT;

So I'm not sure you really need a SAS Macro program. It might be overkill to use a SAS macro program to create a new variable, if that's all you wanted/needed to do. I wonder whether it might be better to read about basic SAS concepts, like DATA step processing and how to write a SAS program. SAS is not a WYSIWYG application (what you see is what you get), like Excel or Word. You can't manipulate SAS variables in the same way that you can manipulate values in a worksheet. A SAS macro program does not operate the same way than an Excel macro operates.

  To effectively use SAS macro programs and macro variables, you really need to understand the basics of using SAS, because the first "rule" of macro is to have a working SAS program. Here's a good paper on the basics of DATA step programming:

http://www.nesug.org/proceedings/nesug08/ff/ff12.pdf

http://www2.sas.com/proceedings/sugi29/269-29.pdf

http://www2.sas.com/proceedings/sugi31/246-31.pdf

and the documentation has some good sections:

http://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#p1bidsfinjj8w4n1ih91...

http://support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n14v4oo5h1p5r0n1ayun...

And, for overview information about SAS Macro processing, this is a good paper:

http://www2.sas.com/proceedings/sugi28/056-28.pdf

  

cynthia


excel_formula.png

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
  • 1 reply
  • 689 views
  • 0 likes
  • 2 in conversation