sasinterviewsquestion

Just another WordPress.com site

SAS Macros Example

For Free Programming Workshops http://www.sastrainingdelhi.in
mob: 9990835485

How do you like the blog content?

(polls)

Question:
Dataset hired is created as
data Hired;
input name $ start;
cards;
Raj 14567
Manoj 14524
Arvin 14579
Ran 14465
Arun 14642
Kirti 14123
Ravin 14523
Suresh 14272
Lalu 14627
Vash 14770
run;

Write a SAS Macro to print all those candidates who are hired in the current month.

Answer:
%macro currenthire;
data current;
set hired;
if month(start) = month(today());
run;
%mend;
%currenthire;

Question:
Create a SAS Macro to combine number of datasets (given below). Also use the macro debugging options.
data file1;
input a @@;
cards;
1 2 3 4
;
run;

data file2;
input a @@;
cards;
5 6 7 8
;
run;
data file3;
input a @@;
cards;
9 10 11 12
;
run;data file4;
input a @@;
cards;
13 14 15 16
;
run;

Answer:
Filename mprint “C:\Users\abc\Desktop\macrores.sas”;
Options mprint mfile mlogic symbolgen ;
%macro combine(n);
data comb;
set
%do i=1 %to &n;
file&i
%end;
;
run;
%mend combine;
%combine(4);

Question:
Dataset xxx is given as:
data xxx;
input v1-v5 ind1 ind2;
cards;
1 0 1 1 0 34 23
0 0 0 1 1 22 32
1 1 0 1 0 12 10
0 1 1 0 1 56 90
;
run;

Create a SAS macro to print 10 reports (5*2) such that first report contains variables v1 ind1, second contains the variables v1 ind2 and so on…

Answer:
%macro mymac(x,y);
%do i=1 %to &x;
%do j=1 %to &y;
proc print data = xxx;
var v&i ind&j;
run;
%end;
%end;
%mend mymac;
%mymac(5,2);

How do you like the blog content?

(polls)

One response to “SAS Macros Example

  1. Manasa February 25, 2015 at 11:31 am

    If i have 100 variables in my data set, and I want to convert all of them into macro variavles. What is the simplified method that I can use?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: