<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Use DATA Step generated array in a proc compile in SAS Risk Management</title>
    <link>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470418#M240</link>
    <description>&lt;P&gt;Hello! I've got a problem handling data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I have to generate a cashflow for some bonds. These bonds are inflation-adjusted, so what I want to do is to get inflation data from an Excel so that I can adjust the principal.&amp;nbsp;&amp;nbsp;I've been able to extract the data from the Excel into a SAS table, according to some relevant criteria. &amp;nbsp;I've been able to assign the data I got from the SAS Table into an array within a DATA Step.&amp;nbsp;The issue comes when I want to use that data. Is there any way to import it into a pricing method generated within a PROC Compile?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't use macros. I need to do this from several bonds at time, and as far as I know&amp;nbsp;if I make a do loop of call symputs I will only get the&amp;nbsp;data for the last bond in the list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I got so far:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = "04APR2018"d;
%let path = "/data/user/Desarrollo_Martin";
libname desa "/data/user/Desarrollo_Martin";


data aa;
set desa.cer;

if ((month(fecha) = 07 or month(fecha)= 01) and  day(fecha) = 22) then
output;

run;

proc sort data= aa out= bb;
by cer;
run;

proc transpose data=bb out=cc prefix=tasas;

var CER;

run;

 
data dd;

set cc;
array ss[*] tasas1-tasas4;
array a (4);
do i = 1 to 4;
a[i] = ss[i];
end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jun 2018 19:21:41 GMT</pubDate>
    <dc:creator>klasko</dc:creator>
    <dc:date>2018-06-14T19:21:41Z</dc:date>
    <item>
      <title>Use DATA Step generated array in a proc compile</title>
      <link>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470418#M240</link>
      <description>&lt;P&gt;Hello! I've got a problem handling data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I have to generate a cashflow for some bonds. These bonds are inflation-adjusted, so what I want to do is to get inflation data from an Excel so that I can adjust the principal.&amp;nbsp;&amp;nbsp;I've been able to extract the data from the Excel into a SAS table, according to some relevant criteria. &amp;nbsp;I've been able to assign the data I got from the SAS Table into an array within a DATA Step.&amp;nbsp;The issue comes when I want to use that data. Is there any way to import it into a pricing method generated within a PROC Compile?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't use macros. I need to do this from several bonds at time, and as far as I know&amp;nbsp;if I make a do loop of call symputs I will only get the&amp;nbsp;data for the last bond in the list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I got so far:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = "04APR2018"d;
%let path = "/data/user/Desarrollo_Martin";
libname desa "/data/user/Desarrollo_Martin";


data aa;
set desa.cer;

if ((month(fecha) = 07 or month(fecha)= 01) and  day(fecha) = 22) then
output;

run;

proc sort data= aa out= bb;
by cer;
run;

proc transpose data=bb out=cc prefix=tasas;

var CER;

run;

 
data dd;

set cc;
array ss[*] tasas1-tasas4;
array a (4);
do i = 1 to 4;
a[i] = ss[i];
end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 19:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470418#M240</guid>
      <dc:creator>klasko</dc:creator>
      <dc:date>2018-06-14T19:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use DATA Step generated array in a proc compile</title>
      <link>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470429#M241</link>
      <description>&lt;P&gt;It's not really clear what you're trying to do here to me at least.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays in SAS are just shortcut references. If you can explain your logic with some sample data and expected output we can probably help you find a solution. I suspect you need to use BY group processing as well, since you're doing this for multiple bonds.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 20:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470429#M241</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-14T20:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use DATA Step generated array in a proc compile</title>
      <link>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470434#M242</link>
      <description>&lt;P&gt;My data comes like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="excel.png" style="width: 268px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21203iC127760406D0498E/image-size/large?v=v2&amp;amp;px=999" role="button" title="excel.png" alt="excel.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose the bond pays on 28/05/2018 and on 30/05/2018. Inflation between these dates is: (9.4052-9.3891)/9.3891. I need to compute the inflation for the previous payments, so that I can adjust the bond principal (it starts at 100).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should look like this, where Mat_Amount is the principal:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="output.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21204i4BAD8F873BED494E/image-size/large?v=v2&amp;amp;px=999" role="button" title="output.png" alt="output.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been able to do it using a proc sql and macros:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Calcula los cash-flows de Titulos */

%let date = "04APR2018"d;
%let path = "/data/user/Desarrollo_Martin";
libname desa "/data/user/Desarrollo_Martin";


data desa.filtrado;
set desa.cer;

if ((month(fecha) = 07 or month(fecha)= 01) and  day(fecha) = 22) then
output;

run;

proc sort data= desa.filtrado out= ordenado;
by cer;
run;

proc sql noprint;
select cer, count(*) into :cer1-:cer20,:cuenta  from ordenado;
*select cer into :emp_list separated by ' ' from desa.cerr;
quit;



data Titulos_Data; 
	length Currency $3 Insttype $20 ; 
	informat Fecha_emision date9. Fecha_vencimiento date9. Fecha_primer_pago date9.; 
	format Fecha_emision date9. Fecha_vencimiento date9. Fecha_primer_pago date9.;
	input insttype $ instid $ Fecha_emision Fecha_vencimiento Fecha_primer_pago Cantidad_pagos_anuales Badlar spread Principal Currency $ holding Feriadosyfinesdesemana; 
	datalines;
Titulos_tasa_fija PR15 22JUL2016 22JUL2021 04JAN2010 2 30 0  100 ARS 1 1

;



run;

data pagosano;
set titulos_data;

call symput('pagosano', Cantidad_pagos_anuales);


call symput('emision', fecha_emision);

call symput('vencimiento', fecha_vencimiento);
%global pagosano; 
%global emision;
%global vencimiento;

run;


proc risk;
	environment new = WORK.Titulos_Flujos;
	environment save;
run;

proc risk; 
	environment open = Titulos_Flujos;
		declare instvars = 
			( 
			Fecha_emision date var label = "Fecha de emision", 
			Fecha_vencimiento date var label = "Fecha de vencimiento",
			Fecha_primer_pago date var label = "Fecha del primer pago",
			Cantidad_pagos_anuales num var label = "Cantidad de pagos de interes anuales",
			Badlar num var label = "Badlar",
			spread num var label = "Tasa fija adicionada a la Badlar",
			Principal num var label = "Principal",
			Feriadosyfinesdesemana num var label= "Un uno traslada la fecha de los pagos en caso de que caigan en feriados/fines de semana, un cero no altera nada"

);

		declare riskfactors = 
			( 
			Precio num var
			);
	environment save;
run;

proc compile
	environment = Titulos_Flujos 
	outlib = Titulos_Flujos 
	package = Titulos_Flujos;

	method Titulos_tasa_fija_CF kind = price;

/* Calcula el numero de pagos usando la fecha de inicio y la de vencimiento */

%macro numerocuotas;

%let j = 1;
%let Stop = %str(N); 
%do %while (&amp;amp;Stop = N);
%let fecha = %sysfunc(INTNX( month, &amp;amp;emision., &amp;amp;j*(12/&amp;amp;pagosano), same ));
%if %sysevalf (&amp;amp;fecha = &amp;amp;vencimiento) %then %let Stop = %str(S);
%if &amp;amp;j =120 %then %let Stop = %str(S);
%let j=%eval(&amp;amp;j+1);
%end;

%global numerocuotas;
%let numerocuotas = &amp;amp;j;
%put &amp;amp;numerocuotas;



%mend numerocuotas;

%numerocuotas;

%put _all_;

Npagos = &amp;amp;numerocuotas -1;


_cashflow_.Num = npagos;


r = .05;
		
/* seteo de fechas */
if Feriadosyfinesdesemana = 0 then do;
			do i = 1 to NPagos;
				_cashflow_.MATDate[i] = INTNX( "month", Fecha_emision, i*(12/Cantidad_pagos_anuales), "same" );
			end;
			end;
		else do;
			do i = 1 to NPagos;
				_cashflow_.MATDate[i] = INTNX( "month", Fecha_emision, i*(12/Cantidad_pagos_anuales), "same" );
				dia = weekday(_cashflow_.MATDate[i]);   /* Dia de la semana del pago original*/
				if dia = 7 then _cashflow_.MATDate[i] = _cashflow_.MATDate[i]+ 2;
				else if dia = 1 then _cashflow_.MATDate[i] = _cashflow_.MATDate[i] + 1;
			end;
			end;
	



		/*dias entre fechas*/	

		array dias[120];


		do i = 1 to NPagos; 
			if i = 1 then do;
					dias[i] =  _cashflow_.MATDate[i] - fecha_emision;
					end;
		else do;
					dias[i] = _cashflow_.MATDate[i] - _cashflow_.MATDate[i-1];
					end;
		end;

/*variaciones CER*/
array capital[120];

array inflacion(120);



%macro pasado;
%DO I = 1 %TO &amp;amp;cuenta.;
inflacion&amp;amp;I. = ((&amp;amp;&amp;amp;cer&amp;amp;I.-&amp;amp;&amp;amp;cer1)/&amp;amp;&amp;amp;cer1)+1;
capital&amp;amp;I. = 100*inflacion&amp;amp;I.;
%END;
%MEND pasado;

%pasado;

%macro futuro;
%let L = &amp;amp;cuenta.;
%do I = &amp;amp;cuenta. %to &amp;amp;numerocuotas;
inflacion&amp;amp;I. = inflacion&amp;amp;L. * (1.01)**&amp;amp;I.;
capital&amp;amp;I. = capital&amp;amp;L. * inflacion&amp;amp;I.;
%end;
%mend futuro;

%futuro;
/*amortizacion y capital AL FINAL del periodo*/
		/* pagos */

		
%macro pagos;
%do i=1 %to &amp;amp;numerocuotas;
_cashflow_.MatAmt[&amp;amp;I.]=capital&amp;amp;I.;
%end;
%mend pagos;

%pagos;	

%put _all_;




	
_value_ = Precio*Principal;
endmethod;
run;






run;

/* Define Instrument Types -*/
proc risk; 
	environment open = Titulos_Flujos; 
		instrument Root1 label = "Common Variables" variables = ( currency , holding ) defaults =( holding 1 ); 
		instrument Titulos_tasa_fija label = "Titulos Tasa Fija" 
			basetype = Root1 
			variables = ( Fecha_emision, Fecha_vencimiento, Fecha_primer_pago, Cantidad_pagos_anuales, Badlar, spread, Principal, Feriadosyfinesdesemana ) 
			methods = ( price Titulos_tasa_fija_CF); 
	environment save;
run;

/*- Create Instrument Data Set -*/


/*- Create Market Data Set -*/
data marketdata; 
	input Precio; 
	datalines;
1.1
;
run;


/*- Register Instrument Data -*/ 
proc risk; 
	environment open = Titulos_Flujos; 
		instdata Titulos_Data 
			file = "Titulos_Data" 
			format = simple 
			label = "Titulos Data" 
			variables = ( insttype instid Fecha_emision Fecha_vencimiento Fecha_primer_pago Cantidad_pagos_anuales Badlar spread Principal Currency holding Feriadosyfinesdesemana ); 
	/*- Portfolio Input Lists -*/ 
		sources Titulos_List Titulos_Data; 
	environment save; 
run;

proc risk; 
	environment open = Titulos_Flujos ; 
		/*- Create Portfolio Files -*/ 
		read sources = Titulos_list out = Titulos_File; 
		/*- Register Market Data Sources After Creating Market Data -*/
		marketdata Marketdata file = Marketdata type = current;
	environment save; 
run;

proc risk; 
	environment open = Titulos_Flujos ;

		cashflow Titulos_Flujos;

		project Titulos_Flujos 
			data = Marketdata
			portfolio = Titulos_File
			analysis = Titulos_Flujos
			numeraire = ARS
			rundate = &amp;amp;date 
			outlib = work
			options = (outall); 

			/*- Run the Project -*/
		runproject Titulos_Flujos;

	environment save;

run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, it works only if I want to compute the amounts for one bond. When I add another one, the computation of both bonds is done using the macro-generated values of only one of the bonds, so it's all messed up.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 20:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470434#M242</guid>
      <dc:creator>klasko</dc:creator>
      <dc:date>2018-06-14T20:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use DATA Step generated array in a proc compile</title>
      <link>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470438#M243</link>
      <description>Please post data as text so we can copy/paste it.</description>
      <pubDate>Thu, 14 Jun 2018 20:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470438#M243</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-14T20:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use DATA Step generated array in a proc compile</title>
      <link>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470448#M244</link>
      <description>&lt;P&gt;Woops, sorry.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There goes the sample data (cerentero) and output (output).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2018 20:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Risk-Management/Use-DATA-Step-generated-array-in-a-proc-compile/m-p/470448#M244</guid>
      <dc:creator>klasko</dc:creator>
      <dc:date>2018-06-14T20:50:54Z</dc:date>
    </item>
  </channel>
</rss>

