BookmarkSubscribeRSS Feed
Yennie
Calcite | Level 5
I found myself repeating the below datastep five times. I know %macro can help me to save the effort of writting the script over and over again. However, I am unsure on how to use it. =/ Hoping someone can help me out!

Proc Summary Data = GIO_VOR Nway Missing;
Class month GioBike_Grp;
Var claimCount epy earnedPrem incurToDate;
Output out = Gccgrp (Drop = _Type_ _Freq_) Sum=;
Run;

Data Gccgrp;
Set Gccgrp;
Length Claims_Frequency 8. Loss_Ratio 8.;
Claims_Frequency = (claimCount/EPY) * 100;
Loss_Ratio = (incurToDate/earnedPrem) * 100;
Run;

Proc Summary Data = GIO_VOR Nway Missing;
Class month GioCover_Type;
Var claimCount epy earnedPrem incurToDate;
Output out = Gcover (Drop = _Type_ _Freq_) Sum=;
Run;

Data Gcover;
Set Gcover;
Length Claims_Frequency 8. Loss_Ratio 8.;
Claims_Frequency = (claimCount/EPY) * 100;
Loss_Ratio = (incurToDate/earnedPrem) * 100;
Run;

Proc Summary Data = GIO_VOR Nway Missing;
Class month GIO_Ageband;
Var claimCount epy earnedPrem incurToDate;
Output out = GAgeband (Drop = _Type_ _Freq_) Sum=;
Run;

Data Gageband;
Set GAgeband;
Length Claims_Frequency 8. Loss_Ratio 8.;
Claims_Frequency = (claimCount/EPY) * 100;
Loss_Ratio = (incurToDate/earnedPrem) * 100;
Run;

Proc Summary Data = GIO_VOR Nway Missing;
Class month GioChannel_Grp;
Var claimCount epy earnedPrem incurToDate;
Output out = Gchannel (Drop = _Type_ _Freq_) Sum=;
Run;

Data Gchannel;
Set Gchannel;
Length Claims_Frequency 8. Loss_Ratio 8.;
Claims_Frequency = (claimCount/EPY) * 100;
Loss_Ratio = (incurToDate/earnedPrem) * 100;
Run;

Proc Summary Data = GIO_VOR Nway Missing;
Class month GioBike_Make;
Var claimCount epy earnedPrem incurToDate;
Output out = Gbikemake (Drop = _Type_ _Freq_) Sum=;
Run;

Data Gbikemake;
Set Gbikemake;
Length Claims_Frequency 8. Loss_Ratio 8.;
Claims_Frequency = (claimCount/EPY) * 100;
Loss_Ratio = (incurToDate/earnedPrem) * 100;
Run;

Much Appreciated.

Yennie
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi:
Reading the macro documentation will probably help you. Consulting any of Art Carpenter or Michele Burlew's macro books will probably help you. Searching for User Group papers (like this one) will probably help you:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

The SAS Macro Facility is a big topic and the best thing to do is to start with a working SAS program (which it looks like you have) and then slowly experiment with "macro-tizing" the program...as described in the 9 steps in the above paper.

cynthia
Yennie
Calcite | Level 5
Hey cynthia!

This is awesome. Thank you!


Cheers
Yennie

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 947 views
  • 0 likes
  • 2 in conversation