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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 325 views
  • 1 like
  • 2 in conversation