Pregunta

I am working on converting a SAS code into R and since I am relatively new to SAS I am having trouble understanding the following code snippet -

proc expand data=A out=B;
by number beg_date; 
id date;
convert alpha1=calpha1/transformout=(+1 cuprod -1); 
convert alpha2=calpha2/transformout=(+1 cuprod -1);
convert alpha3=calpha3/transformout=(+1 cuprod -1);
run;

I understand expand is used for expanding time series data like from monthly to quaterly or contract them. But what are the by and id statements for? From referring to SAS Support, I believe that the BY statement is used to specify the variables so that the cumulative product is calculated for a group of that variable. As for the ID statement, I understand that it is a key to identify the observations.Can anyone tell me if my understanding is correct? Do I used the transform command in R for this purpose? I don't have SAS license so I cannot try this out on a sample data and understand the output. Similarly, I don't have a raw data set to work on.

¿Fue útil?

Solución

From your code snippet, it seems like this proc expand is going to create three variables calpha1, calpha2 and calpha3. cuprod is one of the options in proc expand that is going to output the cumulative product. So this is going to find the product of all alpha1, alpha2 and alpha3 within every beg_date group that was sorted like that in by statement. I believe that there should have been a proc sort before the proc expand for the use of the by statement.

Regarding the ID statement, it seems like original writer didn't want to use the default time settings of proc expand. Thus, by specifying date variable in id statement, the calculations would be based on the points in time given from date.

http://support.sas.com/documentation/cdl/en/etsug/63348/HTML/default/viewer.htm#etsug_expand_sect008.htm

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top