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
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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