×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

write a Macro for the following SAS code

write a Macro for the following SAS code

write a Macro for the following SAS code

(OP)
Hi,

I am actually learning SAS by myself. Can you please help me in creating a macro for this program using infile function instead of using the datalines.


Data file will have the following data. Strore it as problem1.txt

0 1 1 0 -2 6 7 7 4 -3 9 14


Write a macro and store it to compute the sum for the following program

The SAS program without macro goes here.

/* Fisher Randomization test */

CODE

option ls=78;

data xx;

    input y1-y12;
        array ss(*) y1-y12;
    m=4; nn=12;
    
    do n1=1 to nn-m+1;
       do n2=n1+1 to nn-m+2;
       do n3=n2+1 to nn-m+3;
          do n4=n3+1 to nn-m+4;
          do n5=n4+1 to nn-m+5;

    sum=ss(n1)+ss(n2)+ss(n3)+ss(n4)+ss(n5);
      if sum <=0 then t=1; else t=0;
        output;
    end; end; end; end; end;


datalines;

0 1 1 0 -2 6 7 7 4 -3 9 14

run;

/* The main objective is instead of using datalines here, store the data in a file and use infile keyword */

proc univariate noprint;
var t;
    output out=temp n=nn sum=tt;

    data xx;
    set temp;
       pp=tt*2/nn;
       proc print data=xx;
       var tt pp;

run;
Thank you so much in advance.





 

RE: write a Macro for the following SAS code

In this case I think you've gotten a bit mixed up as there is no macro here?

A macro is generally done for code efficiency where something that is coded multiple times and writing a macro saves the coder time. Macros generally do not make your code process faster.

If all you want is to amend the code to use infile rather than datalines then..


option ls=78;

data xx;
    infile C:\problem1.txt dsd missover dlm=' ';    /*This is the location of your text file.
                              dsd and missover are infile options, further reading for you
                              dlm is the delimeter of the read in file*/
    input y1-y12;
        array ss(*) y1-y12;
    m=4; nn=12;
    
    do n1=1 to nn-m+1;
       do n2=n1+1 to nn-m+2;
       do n3=n2+1 to nn-m+3;
          do n4=n3+1 to nn-m+4;
          do n5=n4+1 to nn-m+5;

    sum=ss(n1)+ss(n2)+ss(n3)+ss(n4)+ss(n5);
      if sum <=0 then t=1; else t=0;
        output;
    end; end; end; end; end;


run;

/* The main objective is instead of using datalines here, store the data in a file and use infile keyword */

proc univariate noprint;
var t;
    output out=temp n=nn sum=tt;

    data xx;
    set temp;
       pp=tt*2/nn;
       proc print data=xx;
       var tt pp;

run;
 

RE: write a Macro for the following SAS code

(OP)
Please help with this SAS code.
Below is the question that describes in detail.

file1.txt X   4 3 1 2 7 5 5
file2.txt Y  20 7 8 5 2 4 15

X-Y=         -16 -4 -7 -3 5 1 -10

Write a macro for the following SAS code and store it so that it can be used to run on different data sets.
1. Read the data
2. Find the difference
3. Create a subfile that has only positive difference
4. Find the sum


The SAS Code
dm log 'clear';
dm output 'clear';
options ls=78;

data xx;
input y1-y7;
array ss(*) y1-y7;
array x(*) y1-y7;

do n1=1 to 2; if n1=1 then x(1)=ss(1); else x(1)=0;
do n2=1 to 2; if n2=1 then x(2)=ss(2); else x(2)=0;
do n3=1 to 2; if n3=1 then x(3)=ss(1); else x(3)=0;
do n4=1 to 2; if n4=1 then x(4)=ss(1); else x(4)=0;
do n5=1 to 2; if n5=1 then x(5)=ss(1); else x(5)=0;
do n6=1 to 2; if n6=1 then x(6)=ss(1); else x(6)=0;
do n7=1 to 2; if n7=1 then x(7)=ss(1); else x(7)=0;

sum=x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7);
if sum<=6 then t=1; else t=0;
output;
end;end;end;end;end;end;end;

datalines;
16 4 7 3 5 1 10
run;

proc univariate noprint;
var t;
output out=temp n=nn sum=tt;
run;

data xx;
set temp;
pp=tt*2/nn;
run;


proc print data=xx;
var tt pp;
run;


Thank you in advance.
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close