On Wed, 13 Jul 2005 19:37:55 -0400, Robert Slotpole <rslotpole@COMCAST.NET>
>I keep working through the tutorials but there are so many of them. I know
>this is a verry basic question but just the same any and all help greatly
OK. But posting essentially the same question multiple times under
different subject headings isn't really going to accomplish much.
>In my main table D6 I have 200 observations consisting of 40 tickers
>repeated for each of 5 dates. I issue a proc summary by date and get 5
>observations (1 for each date) that I now want to add to one of the
>The code I tried was:
>proc summary data=d6;
> var dollar_div;
> by date;
> output out=d7 sum=total_dol_div;
> set d7;
> keep total_dol_div;
What you've done here is create a new D7 from the existing D7. The KEEP
preserves TOTAL_DOL_DIV but by implication sheds DATE (which I think you'll
need) and _TYPE_ and _FREQ_ (automatic variables created by PROC SUMMARY,
which you probably won't need). You've also missed an opportunity to add
the variable TICKER, which I think you will need (see below).
drop _type_ _freq_;
ticker = '*$$$';
> set d6;
> if ticker = '*$$$' then trade = trade + total_dol_div;
>I thought the keep command would keep total_dol_div but I get: NOTE:
>Variable total_dol_div is uninitialized.
Remember that TOTAL_DOL_DIV is in D7, and you've not introduced D7 in this
step. Since you reference TOTAL_DOL_DIV, SAS creates it, but without the
benefit of any value to load into it.
>I could do a merge but that seems like it would be very wasteful of
What makes you think a merge is wasteful (not that wastefulness could even
be detected with 200 observation)? A merge is exactly what you need.
merge d6 d7;
by date ticker;
if ticker = '*$$$' then trade = trade + total_dol_div;
If you did not have TICKER in D7, this would not work (see above).
>also, each observation is uniquely defined if you can specify ticker and
>date. How can I access a specific record and change the contents? e.g.
>if ticker = '*$$$' AND date = '12-31-2003' then trade =trade + 10000000;
I advise against such extensive hard-coding. SAS works best for you if you
exploit its features, many of which are designed for data-driven (as
opposed to code-driven) operation. Sometimes you have to condition and even
contrive the data a little.
>Obviously that doesn't work but how would you identify an unique
>observation? Would this work:
I know of no DO statement having this form. You can't just make stuff up,
and you should not assume that a construct or bit of syntax you know from
another language will work in SAS.
> if date ='12-31-2003' then do ticker;
> if ticker='*$$$' then trade = trade + 10000000;
>going back to the first problem, could we use this logic to solve that
>problem also? e.g.
> do ticker;
> if ticker ='*$$$' then trade = trade + total_dol_div;
>suggestions, comments? help...
Also, using descriptive names (not D1, D2, .... Dn) might help you, and
anyone reading your code, to keep track of what's what.