BookmarkSubscribeRSS Feed
nottp
Fluorite | Level 6

I have this data

nottp_0-1591675644773.png

 

I want to loop for find average price every stock name and I write this Proc Sql but it can fine one stock name. please advise me.

proc sql;
create table avg_price_30D_work as
select distinct
&batch_date. as data_dt format yymmdd10.,
stk_shrt_nm,
avg(close_price) as avg_price_30D_work
from work.stock_price_cal
where 1=1
and cnt_wk between (select cnt_wk-29 from work.stock_price_cal where 1=1 and DATA_DT = &batch_date. and stk_shrt_nm = "AJ") 
and (select cnt_wk from work.stock_price_cal where 1=1 and DATA_DT = &batch_date. and stk_shrt_nm = "AJ")
;
quit;

 

1 REPLY 1
Kurt_Bremser
Super User

DO NOT POST DATA IN PICTURES!

Please post your dataset as a data step with datalines; include all columns used in your SQL.

SQL does not have loops, but you can use GROUP BY to create results for groups.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 442 views
  • 1 like
  • 2 in conversation