BookmarkSubscribeRSS Feed
Nargess
Calcite | Level 5

I am a newbie in SAS programming. I was wondering if it is possible to open a SAS file in a macro and use its variables to do some calculations?

to be more specific, I am trying to write a macro for changing currencies to AUD but not the current rates to get it from a live data source rather I need historical rates. So I have the historical exchange rates downloaded from Reserve bank of Australia and already imported to SAS. But have not yet figured out how to write a macro to open the file and use its values. Something that I have tried is the following:

%macro convert_currency(x,CUR,Date);

%let fopen(exchange_rates,I);

%IF exchange_rates.date=&date %then Rate=&CUR;

%let &x._convert=&x*rate;

run;

%mend convert_currency;

I will be thankful if someone can help.

1 REPLY 1
SASKiwi
PROC Star

If by SAS file you mean a SAS dataset then I suggest you use a SAS DATA step for that. BTW the FOPEN function is for external files, usually text, and not SAS datasets.

To start with just build a simple DATA step without using a macro, then once that is working, convert it to a macro:

data new;

  set old;

  currency_aud = currency * rate;

run; 

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
  • 719 views
  • 0 likes
  • 2 in conversation