BookmarkSubscribeRSS Feed
sspkmnd
Obsidian | Level 7

I need to allocate memory (directly in RAM), then write values to it, and then read them. There are a set of SAS functions usually references as APP: ADDR, PEEK, PEEKC, the CALL POKE routine, and their so-called LONG 64-bit counterparts. There are several papers with many examples on how to do so:

  1. Paper 1510-2014 Direct Memory Data Management Using the APP Tools
  2. SUGI 29 Paper 264-29 A-P-P Advanced Data Management Functions

but only in the case of using SAS data step. Allocation memory in this case is just declaring a variable (not really a runtime case, but at least something).

 

 

data debug;
    length v $200;
    pv = addrlong(v);
    call pokelong('just a value', pv);
    v2 = peekclong(pv);
    put 'address: ' pv $hex16.;
    put 'value:   ' v2;
run;

/*
address: 9FFFFFFFEC0A18B0
value:   just a value
*/

 

I need to "migrate" this to pure SAS macro. The first problem which I don't how to resolve is how to allocate memory - receive a pointer where I can write to. Does anyone have any ideas?
 
 
Thanks and kind regards,
Igor
7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't see how you can.  Macro is not and executable language.  It is a text find replace system.  It is there to simplify the task of writing text, nothing else.  

Personally, I would advise that if you having to use these kind of functions in the first place, there is something wrong with the process, and putting it into macro is only going to exacerbate your problems.  There are other ways of working with large numbers.

snoopy369
Barite | Level 11
I think you need to explain more of what you're doing. You're not going to be able to use the macro language in %SYSFUNC etc. to just write directly to random memory.

Can you post a short, runnable example of a function that you'd like to turn into pure macro language, and why you want to do so?
sspkmnd
Obsidian | Level 7
The code is in the question, I need to do the same using SAS macro: allocate memory, write to it, read it.
Patrick
Opal | Level 21

@sspkmnd

Why? Is this just an experiment or is this for an actual use case? And if it's for an actual use case then can you please explain what you have and what you're actually trying to achieve? Using pokelong() etc. is something rarely done and needed.

 

@RW9 wrote it already but here again: SAS Macro language is your "automatic typewriter" allowing you to dynamically generate SAS code which then gets executed. Why does this need to be in a macro?

If you just want to write your own function or call routine then may be have a look into Proc FCMP. 

sspkmnd
Obsidian | Level 7
Completely agree with you that question is kinda weird. But I am interested if this actually possible.
Tom
Super User Tom
Super User

What do you want to poke into memory?

Are you trying to find a way to take advantage of the newly announce MELTDOWN security bug in INTEL processors?

 

sspkmnd
Obsidian | Level 7

I expected this answer Smiley Happy but no. And this can be exploited in SAS data step if actually possible to exploit in SAS, no need in pure SAS macro. I was just interested in possibility of memory management using pure SAS macro.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1956 views
  • 0 likes
  • 5 in conversation