BookmarkSubscribeRSS Feed
ivyc
Calcite | Level 5

Hi All,

I am new to SAS  macros and I am literally awful at doing it !

I have 100 random digits 00-99 and want to t-test their interaction  with SAS.

For example test cell 00 with 1-99 other cells,test cell 1 with 00 and 2-99 cells.

Is there a way to write a macro that will do this ?

So  say i=00-99 and j=00-99;

run the test if i=00 with j which is between 1 and 99 .if i=j then do not test so do not test same cells .

Is there an easy way to do this ?

Please help

Thanks in advance

Ivy

9 REPLIES 9
Reeza
Super User
If you can show how the code would work for a single case we can likely help make it into a macro - or suggest code that would do the test without a macro. It would also help if you explained your data structure. Feel free to use data in the SASHELP library or generate random data using RAND() functions.
ivyc
Calcite | Level 5
So I have 100 random digits that have values 00 to 99.
I want to test their interaction using ttest(i am OK with writing SQL code).
So I am testing random digit 00 with random digit 1,then 00 with random digit 2,etc all the way to testing 00 and 99.
Then I want to test random digit 1 with 00,1 with 2,1 with 3,1 with 4 ,etc all the way 1 to 99.and all the way up to testing 99 digit with 00,99 with 1,99 with 2 etc.
I need to come up with the macro that will run this many iterations.
Can you help me with that?
Reeza
Super User

If you provide the base case (sample data and code for t-test) I'm happy to help turn this into a macro. Otherwise I'm sure someone else will be along. 

 


@ivyc wrote:
So I have 100 random digits that have values 00 to 99.
I want to test their interaction using ttest(i am OK with writing SQL code).
So I am testing random digit 00 with random digit 1,then 00 with random digit 2,etc all the way to testing 00 and 99.
Then I want to test random digit 1 with 00,1 with 2,1 with 3,1 with 4 ,etc all the way 1 to 99.and all the way up to testing 99 digit with 00,99 with 1,99 with 2 etc.
I need to come up with the macro that will run this many iterations.
Can you help me with that?

 

PaigeMiller
Diamond | Level 26

As @Reeza said, show us code with no macros that works on one instance of doing this t-test, and the we can help turn this into a macro.

 

Also, it is not clear how a t-test applies to this case of 100 random digits, it is unclear what response variable is used in the t-test, it is unclear what hypothesis is being tested.

--
Paige Miller
ballardw
Super User

@ivyc wrote:
So I have 100 random digits that have values 00 to 99.
I want to test their interaction using ttest(i am OK with writing SQL code).
So I am testing random digit 00 with random digit 1,then 00 with random digit 2,etc all the way to testing 00 and 99.
Then I want to test random digit 1 with 00,1 with 2,1 with 3,1 with 4 ,etc all the way 1 to 99.and all the way up to testing 99 digit with 00,99 with 1,99 with 2 etc.
I need to come up with the macro that will run this many iterations.
Can you help me with that?

Actual example data might help.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Terminology: '00' is not a digit. 0 1 2 3 4 5  6 7 8 9  are digits and for most purposes digits are character. So ttest involving means would be meaningless.

 

What comparison of "random digit 1 with 00'? Actual values and the type of comparison are critical

 

I suspect that you may mean that have VARIABLES possibly in some order that you want to compare .

If you are looking for some kind of paired comparison where the question is about the differences between variables per record then the TTEST option Paired may be what you want and it supports list processing such as

 

PAIRED (V1 - V10) * (Y1 - Y100);

which would do paired tests with each variable from  V1 to V10 paired with each variable from Y1 to Y100.

ivyc
Calcite | Level 5
This is the code :

%macro runit(no);

title 'BeaconScr';
proc ttest data=stacked2 cochran ci=equal umpu ;
class cell_ind;
var beacon_scr; /*** change this ****/
where beacon_scr>350 and cell_ind in ("CELL&no.","CELL&mo") ; /*** change this ***/
run;

%mend;


%macro repull;
%do i = 00 %to 99;
%let I = &i;
%runit(&i);
%end;
%mend;

%repull;
I need to write macro to define cell&mo.So if cell&no has value of lets say 2 ,I am testing it against allother 99 values of Cell&mo.So cell&mo. has all values other than 2.To me that is a tricky part to define in macros.Thanks
Reeza
Super User
How can you test one value against a series of values - you could test if the mean of all the other values was equal to a specific value, but I'm guessing I don't understand your data structure. I really thing you need to provide sample data here-make some basic fake data in Excel and show a few of the calculations needed to illustrate your problem.
PaigeMiller
Diamond | Level 26

Show us a portion of your actual SAS data set stacked2, following these instructions: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

--
Paige Miller
ballardw
Super User

@ivyc wrote:
This is the code :

%macro runit(no);

title 'BeaconScr';
proc ttest data=stacked2 cochran ci=equal umpu ;
class cell_ind;
var beacon_scr; /*** change this ****/
where beacon_scr>350 and cell_ind in ("CELL&no.","CELL&mo") ; /*** change this ***/
run;

%mend;


%macro repull;
%do i = 00 %to 99;
%let I = &i;
%runit(&i);
%end;
%mend;

%repull;
I need to write macro to define cell&mo.So if cell&no has value of lets say 2 ,I am testing it against allother 99 values of Cell&mo.So cell&mo. has all values other than 2.To me that is a tricky part to define in macros.Thanks

I think that you may need to provide to us at least the explicit values you need. The value of &I you are attempting to use is not what I think you need. Consider:

%macro dummy;
%do i = 00 %to 10;
%put i is &i.;
%end;
%mend;
%dummy

Examine the log to see the values. The value of &I is not 00, it is 0. And if you were expecting to generate something like 01 02 etc then you need to show us because the code you have now is not doing it.

Instead of hiding things with macro code, show the EXACT Proc ttest code you need to generate for a few values of &no, &mo. No macro variables anywhere. Complete Proc Ttest code from Proc statement to Run statement.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 9 replies
  • 2059 views
  • 0 likes
  • 4 in conversation