Similar Threads
1. Hi Regarding visual basic
2. FW: A MACRO HELP NEEDED - I am new in Macro (please help me)
> -----Original Message-----
> From: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] On
> Behalf Of Tom Smith
> Sent: Monday, May 19, 2008 1:45 PM
> To: XXXX@XXXXX.COM
> Subject: A MACRO HELP NEEDED - I am new in Macro (please help me)
>
> I have a sample code as below:
>
>
> %Macro select (AgB, CAB);
>
>
> if &AgB = '1' then AgB = "Aucun sympt^ome";
> else if &AgB = "2" then AgB = "Atteinea";
> else if &AgB = "3" then AgB = "Atteineb";
> else if &AgB = "4" then AgB = "Atteinec";
> else if &AgB = "p" then AgB = "Atteined";
> else if &AgB = "q" then AgB = "Atteinee";
> else if &AgB = "z" then AgB = "Atteinef";
> if &CAB = '1' then CAB = "Aucun sympt^ome";
> else if &CAB = "2" then CAB = "Atteinea";
> else if &CAB = "3" then CAB = "Atteineb";
> else if &CAB = "4" then CAB = "Atteinec";
> else if &CAB = "p" then CAB = "Atteined";
> else if &CAB = "q" then CAB = "Atteinee";
> else if &CAB = "z" then CAB = "Atteinef";
> run;
>
> %Mend select;
> %select (Choutri, Passenger)
> run;
>
>
>
>
>
>
> Now there is a repitation of the same group of statements or group of
> codes twice ( actually
> in the original program there is hundreds time repitaion).
> How can I put
> those
> repeted statements or codes in a Macro? The program already
> has a Macro
> select.
>
Tom
When beginning to learn macro it is important to keep in mind two concepts (among others):
1. macro and data step code are run at different times.
2. macro processing is text substitution (over-simplified but essentially true).
It looks like you might be inappropriately mixing macro and data step code. At the very least your choice of macro parameter names may be confusing.
If you want to include the macro generated statements more than once in a program then just include the macro call more than once
Data want;
set have;
...
%select(v1,v2)
... More statements
%select(v3,v4)
...
Run;
But as Ron Fehd has pointed out, macro may not be the tool that you want to use to solve your problem. Why are you using macro code at all here. What is the problem that macro is supposed to solve for you that you can't use plain old data step code for?
If you tell us more about what you are trying to accomplish, someone may be able to give you better advice.
Dan
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
3. A MACRO HELP NEEDED - I am new in Macro (please help me)
4. Help: computing basic stats by group
5. Basic Logistic Regression Help....plz?
6. Need help with basic IML, "RTFM"
Hi.
I'm trying to do a basic task in IML and failing miserably. This is a
true "RTFM" question, so if that offends you, please read no further.
I want to read a data set into IML, run a procedure, and put the output
into a data set. Here is what happened:
1659 proc iml ;
NOTE: IML Ready
1660
1661 use inds (drop = idvar) ;
1662 read all var _num_ into datamat ;
NOTE: I/O required temporary file to be opened.
1663 optn = j(8,1,.) ;
1664 optn[1] = 0 ;
1664! /* print nothing */
1665
1666 CALL MCD(sc,xmcd,dist,optn,datamat) ;
1667
1668 colnams = {"mahalanobis" "robust" "q975weight"} ;
1669
1670 create distout from dist[colname = colnams] ;
NOTE: Initial allocation of symbol space exhausted. You may specify
SYMSIZE= option on PROC IML
statement to increase its allocation for more efficiency.
1671
1672 quit ;
NOTE: Exiting IML.
NOTE: The data set DISTOUT has 0 observations and 10000 variables.
NOTE: PROCEDURE IML used:
real time 22.28 seconds
cpu time 5.87 seconds
NOTES:
1) The data set, inds, has 10,000 records and around 400 variables.
2) All the variables are numeric, and all except the id variable
("idvar") are to be used in the MCD procedure. I dropped the idvar in
order to keep it out of the MCD procedure. I would prefer to keep it and
not use it, but if the output comes out in the right order, it doesn't
matter.
3) The dist matrix should have 10,000 rows and three columns. The three
columns are mahalanobis distance, robust distance, and weight (in that
order, according to the documentation).
4) I want to output the dist matrix to the data set, distout.
5) I tried to provide names for the columns of distout by creating a
matrix of names, colnams, to be used in the create statement. I didn't
find the documentation very helpful for this.
6) I expected the output data set to have 10,000 rows and three columns.
As you can see, it has 10,000 columns (and came out empty).
How can I get what I want?
Thanks!
-- TMK --
"The Macro Klutz"
7. Multiple ELSEs, was: Retain and Basic SAS help
8. Retain and Basic SAS help
The following code:
data cmp_7;
set cmp_6;
retain endshare;
by ticker date;
if first.date then if ticker = '*$$$' then startshare = 0;
** startshare depends on retained value of endshare;
else if not first.date then if ticker = '*$$$' then startshare =
endshare;
** endshare depends on new value of startshare;
if ticker = '*$$$' then endshare = startshare + tot_dol_div
+tot_sales+tot_purchases;
run;
proc print data=cmp_7;
where ticker='*$$$';
var date ticker startshare endshare price tot_dol_div tot_sales
tot_purchases;
run;
IS PROducing the following output:
tot_dol_ t_
TICKER startshare endshare PRICE div sales
purchases
*$$$ 0 0.00 1 0.00 9617604
-9617604
*$$$ 0 -184845.50 1 17028.50 789484
-991358
*$$$ 0 675.25 1 20471.25 667704
-687500
*$$$ 0 42797.84 1 12244.84 760469
-729916
*$$$ 0 12764.50 1 12764.50 0
0
THE OUTPUT that I am trying to get is:
0 0
0 -184845.50
-184845.50 -184170.25
-184170.50 -141372.41
-141372.41 -128607.91
all other numbers stay the same.
You will notice that in the actual ouput div + purchase + sales =
endshare
and the difference between what I'm getting is I'm not accumulating the
previous value of endshare.
I thought the retain would place the old value of endshare into
startshare and then I could add the last three columns to get the new
endshare. I did something close to this before and it worked. I think
the problem is with the staement if not first.date but I'm not getting
an error.