SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
mikelau
Calcite | Level 5

Hi all,

 

I've run into an issue with using an output statement within DS2 code in SAS MAS module. I had been using ds2 codes in a procedural window for my projects in SAS ESP 5.1. However in ESP 5.2, the DS2 codes need to be converted into functions in SAS MAS modules (in calculate windows) in order to be used. It seems like the output statement doesn't work after the conversion. I make use of the following code:

 

ds2_options sas;
package p1/overwrite=yes;


method test(bigint esp_id, in_out char test);
do i=1 to 3;
test='a';
output;

test='b';
output;

test='c';
output;
end;
end;
endpackage;

 

A simple example. I would like to output 3 rows for every esp_id that comes in within my calculate window:

 

esp_id=0 test='a'

esp_id=0 test='b'

esp_id=0 test='c'

esp_id=1 test='a'

esp_id=1 test='b'

esp_id=1 test='c'

 

but the window only outputs the last one (test='c') for each esp_id. I would really appreciate if someone knows how to solve this. 

 

Mike

 

3 REPLIES 3
s_lassen
Meteorite | Level 14

No idea if this will do, but if the problem is that the last output statement overwrites the others, you could try a loop with a single output statement:

method test(bigint esp_id, in_out char test);
  do test='a','b','c';
    output;
    end;
end;

I do not understand why you have the do loop with the variable i in your original code, though.

mikelau
Calcite | Level 5

Hi s_lassen, thank you for responding. Yes indeed, it seems like last output statement overwrites the others. Using your code, the Module 'test' failed to compile in user context. It seems like 'do' followed by character value causes the error. I have modified the code to:

 

method test(bigint esp_id, in_out bigint test);
 do test=1,2,3;
    output;
end;
end;

 

do followed by a numeric value works, but it only outputs test=3:

 

output.jpg

mikelau
Calcite | Level 5

Hi guys,

 

a small update. After looking into the documentation of SAS® MicroAnalyticService 5.2: Programming and Administration Guide:

 https://documentation.sas.com/api/docsets/masag/5.2/content/masag.pdf?locale=en

 

In chapter 5 (DS2 Programming for SAS Micro Analytic Service), it is mentioned that output statements are not supported. Does anyone know an alternative for the output statement in this case?

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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