05-28-2019
Costasg
Calcite | Level 5
Member since
07-08-2011
- 75 Posts
- 0 Likes Given
- 0 Solutions
- 2 Likes Received
-
Latest posts by Costasg
Subject Views Posted 3784 10-02-2016 10:15 AM 3803 09-30-2016 08:42 AM 3827 09-29-2016 02:07 PM 3838 09-29-2016 04:22 AM 3867 09-28-2016 01:23 PM 1449 09-23-2016 06:01 AM 1478 09-23-2016 05:24 AM 2047 03-20-2015 02:05 PM 2047 03-19-2015 09:37 AM 2218 03-18-2015 05:34 PM -
Activity Feed for Costasg
- Posted Re: Help with code on SAS Procedures. 10-02-2016 10:15 AM
- Posted Re: Help with code on SAS Procedures. 09-30-2016 08:42 AM
- Posted Re: Help with code on SAS Procedures. 09-29-2016 02:07 PM
- Posted Re: Help with code on SAS Procedures. 09-29-2016 04:22 AM
- Posted Help with code on SAS Procedures. 09-28-2016 01:23 PM
- Posted Re: Delete variables by label criteria on SAS Procedures. 09-23-2016 06:01 AM
- Posted Delete variables by label criteria on SAS Procedures. 09-23-2016 05:24 AM
- Got a Like for Delete duplicate rows if two variables match. 08-11-2015 10:10 PM
- Got a Like for Re: Transpose Variables. 03-20-2015 02:08 PM
- Posted Re: Transpose Variables on SAS Procedures. 03-20-2015 02:05 PM
- Posted Re: Transpose Variables on SAS Procedures. 03-19-2015 09:37 AM
- Posted Transpose Variables on SAS Procedures. 03-18-2015 05:34 PM
- Posted Re: Macro for multiple GARCH Regressions on SAS Procedures. 02-28-2015 05:36 AM
- Posted Macro for multiple GARCH Regressions on SAS Procedures. 02-26-2015 02:15 PM
- Posted Re: Character to Date on SAS Procedures. 10-02-2013 04:58 PM
- Posted Character to Date on SAS Procedures. 10-02-2013 09:11 AM
- Posted Re: Missing observations and reorder variables on SAS Procedures. 06-22-2013 01:28 PM
- Posted Missing observations and reorder variables on SAS Procedures. 06-22-2013 10:32 AM
- Posted Re: Keep consecutive observations only on SAS Procedures. 05-26-2013 07:31 PM
- Posted Re: Keep consecutive observations only on SAS Procedures. 05-26-2013 01:09 PM
-
My Liked Posts
Subject Likes Posted 1 07-30-2011 01:28 PM 1 03-20-2015 02:05 PM
09-30-2016
08:42 AM
I managed to figure out a way to do what I want by transposing the two datasets and merging them. If someone has any suggestions on how to make this faster, please feel free to comment.
By the way, how could I create a macro to count the variables in order not to mannually write each time COL1--COL25 and then in each of the arrays the number of variables?
*Import Datasets;
PROC IMPORT OUT=PRICE
DATAFILE= "C:\Users\Laptop\Desktop\DATA.xlsx"
DBMS=XLSX REPLACE;
SHEET="Sheet1";
GETNAMES=YES;
RUN;
PROC IMPORT OUT=FR
DATAFILE= "C:\Users\Laptop\Desktop\DATA.xlsx"
DBMS=XLSX REPLACE;
SHEET="Sheet2";
GETNAMES=YES;
RUN;
*Remove all variables with 'Error';
data price;
set price;
drop _ERR: ;
run;
data fr;
set fr;
drop _ERR: ;
run;
*transpose and sort tables;
proc transpose data=price out=pr(rename=(col1=Price));;
by date;
var TELECOM_ARGENTINA--GRUPO_FINO_GALICIA_DEAD___DELIST;
run;
proc sort data=pr;
by date _LABEL_;
run;
proc transpose data=fr out=fr2(rename=(col1=FR));;
by date;
var TELECOM_ARGENTINA--CENTRAL_PUERTO_SOCIEDAD_ANONIMA;
run;
proc sort data=fr2;
by date _LABEL_;
run;
*merge tables;
data data;
merge pr fr2;
by date _LABEL_;
run;
*keep observations with FR>5;
data data2;
set data;
where Fr>5;
drop FR _NAME_;
run;
*Transpose table;
proc transpose data=data2 out=data3(drop=_NAME_);
by DATE;
run;
*Calculate Cross Sectional Absolute Deviation of Returns;
data Step1;
set data3;
N= n(of COL1--COL25);
array vars(*) COL1--COL25;
array diff(25);
do i=1 to dim(vars);
diff(i)=log(vars(i)/lag(vars(i)));
end;
Average= mean(of diff1-diff25);
array var(*) diff1--diff25;
array ar(25);
do i=1 to dim(var);
ar(i)=(var(i)-average);
end;
array vas(*) ar1--ar25;
array ab(25);
do i=1 to dim(vas);
ab(i)=abs(vas(i));
end;
run;
data Step2;
set Step1;
CSAD= sum(of ab1-ab25)/n;
abs=abs(Average);
sqr=Average*Average;
keep date average CSAD abs sqr;
if CSAD=0 then delete;
run;
... View more
09-29-2016
02:07 PM
Hi ballardw,
Please see the attached excel file. This is how the data is downloaded from Datastream. The stock prices are in Sheet 1 (e.g. TELECOM ARGENTINA) and the foreign holdings (FR) in Sheet 2 (e.g. TELECOM ARGENTINA - FOREIGN HOLDINGS). So, I would like to keep the stock price of TELECOM ARGENTINA for every observation only when TELECOM ARGENTINA - FOREIGN HOLDINGS is greater than 5 for the same observation.
I just thought that it would be easier to have the same names in the two databases and maybe merge somehow the two of them.
I hope this helps.
... View more
09-29-2016
04:22 AM
Thanks for your reply. Data is from Thomson Datastream so this is what I have to work with. Sheet 1 contains prices and Sheet 2 contains FR for the same stocks (not all stocks have a vailable data on FR, so these are less). So, what I want to do is keep the observations in prices (sheet1 or dataset Prices) only when for the same day the FR of the company is >5 (Sheet 2 or dataset FR). Eventually what I want to do seems like that:
data prices;
input Date $ 1-10 ARG YPF BBVA CENTRAL ;
cards;
01/01/2003 3.21 5.27 7.23 9.88
02/01/2003 3.23 5.30 7.20 9.78
03/01/2003 3.26 5.32 7.18 9.70
04/01/2003 3.23 5.38 7.20 9.71
05/01/2003 3.20 5.35 7.19 9.80
;;;
data FR;
input Date $ 1-10 ARG YPF BBVA CENTRAL ;
cards;
01/01/2003 3 11 7 .
02/01/2003 3 11 7 .
03/01/2003 3 11 7 .
04/01/2003 6 11 4 .
05/01/2003 6 11 4 .
;;;
data need;
input Date $ 1-10 ARG YPF BBVA CENTRAL ;
cards;
01/01/2003 . 5.27 7.23 .
02/01/2003 . 5.30 7.20 .
03/01/2003 . 5.32 7.18 .
04/01/2003 3.23 5.38 . .
05/01/2003 3.20 5.35 . .
;;;
... View more
09-28-2016
01:23 PM
Hello,
I have two datasets, one with stock prices and the other with Foreign Ownership (See sample attached). I want to calculate the cross sectional deviation of returns (CSAD), based on the level of foreign ownership of each firm.
Specifically, instead of calculating CSAD on all stocks (as in my code), I want to calculate this on stocks with FR>5; so for each day only the firms with FR>5, which is on the second dataset, should be used in order to calculate CSAD in the "data Step1" command .
Another thing I would like to do is create a macro variable with the number of stocks, so that I don't have to manually adjust these on each dataset (numbers in arrays)
Any ideas to sort these out?
Many thanks in advance.
*Import Datasets;
PROC IMPORT OUT=PRICES
DATAFILE= "C:\Users\Laptop\Desktop\DATA.xlsx"
DBMS=XLSX REPLACE;
SHEET="Sheet1";
GETNAMES=YES;
RUN;
PROC IMPORT OUT=FR
DATAFILE= "C:\Users\Laptop\Desktop\DATA.xlsx"
DBMS=XLSX REPLACE;
SHEET="Sheet2";
GETNAMES=YES;
RUN;
*Remove all variables with 'Error';
proc sql noprint;
select trim(compress(name))
into :drop_vars separated by ' '
from SASHELP.VCOLUMN
where libname = upcase('WORK')
and
memname = upcase('PRICES')
and
upcase(name) like '%ERROR%'
;
quit;
%put &drop_vars.;
data PRICE;
set PRICES;
drop &drop_vars.;
run;
proc sql noprint;
select trim(compress(name))
into :drop_vars separated by ' '
from SASHELP.VCOLUMN
where libname = upcase('WORK')
and
memname = upcase('FR')
and
upcase(name) like '%ERROR%'
;
quit;
%put &drop_vars.;
data FR2;
set FR;
drop &drop_vars.;
run;
*Calculate Cross Sectional Absolute Deviation of Returns;
data Step1;
set PRICE;
N= n(of TELECOM_ARGENTINA--GRUPO_FINO_GALICIA_DEAD___DELIST);
array vars(*) TELECOM_ARGENTINA--GRUPO_FINO_GALICIA_DEAD___DELIST;
array diff(179);
do i=1 to dim(vars);
diff(i)=log(vars(i)/lag(vars(i)));
end;
Average= mean(of diff1-diff179);
array var(*) diff1--diff179;
array ar(179);
do i=1 to dim(var);
ar(i)=(var(i)-average);
end;
array vas(*) ar1--ar179;
array ab(179);
do i=1 to dim(vas);
ab(i)=abs(vas(i));
end;
run;
data Step2;
set Step1;
CSAD= sum(of ab1-ab179)/n;
abs=abs(Average);
sqr=Average*Average;
keep date average CSAD abs sqr;
run
... View more
09-23-2016
05:24 AM
Hello,
I would like to remove some variables based on some criteria in their label. Specifically, I want to delete 'B' shares but these are only mentioned in the label and not in the name of the variable.
For example:
Name: INSTITUTO_ROSENBUCH_DE_BIOLOGIA
Label: INSTITUTO ROSENBUCH DE BIOLOGIA 'B'
The code I used to apply for names is the following, but how can I transform it to use it on labels (if possible)?
proc sql noprint;
select trim(compress(name))
into :drop_vars separated by ' '
from SASHELP.VCOLUMN
where libname = upcase('WORK')
and
memname = upcase('Sample')
and
upcase(name) like '%ERROR%'
;
quit;
%put &drop_vars.;
data data2;
set Sample;
drop &drop_vars.;
run;
Many thanks in advance!
... View more
03-20-2015
02:05 PM
1 Like
Many thanks to everyone for the replies. I decided to go with the arrays.
... View more
03-19-2015
09:37 AM
Hi Reeza, Thanks for your reply. With only one variable, it is easy to transpose.The code would look something like that: proc sort data=data; by company_name;run; proc transpose data=data out=data2; by company_name; run; data data3; set data2 (rename=(col1=Interest_paid)); year=substr(_NAME_,5); drop _name_ ; run; However, I have more than 100 variables, such as Interest paid, Dividend, etc., which have the form of Interest paid 2015, Interest paid 2014.......Interest paid 2005, Dividend 2015......Dividend 2005, etc. So, what I want to do is create a Year Variable and then have one Variable for Interest paid, Dividend, etc. Is there any way to do that? I steel cannot upload any data but this is what I want: HAVE: Company name Country Region BvD ID number ISIN number Date of incorporation Accounting practice 2013 Accounting practice 2012 Accounting practice 2011 Accounting practice 2010 Operating revenue (Turnover) th GBP 2013 Operating revenue (Turnover) th GBP 2012 Operating revenue (Turnover) th GBP 2011 Operating revenue (Turnover) th GBP 2010 P/L before tax th GBP 2013 P/L before tax th GBP 2012 P/L before tax th GBP 2011 P/L before tax th GBP 2010 1 BP P.L.C. UNITED KINGDOM London SW1Y GB00102498 GB0007980591 14/04/1909 IFRS IFRS IFRS IFRS 239,218,000 238,871,000 248,673,000 197,310,000 18,246,000 11,571,000 24,988,000 -3,082,000 2 VOLKSWAGEN AKTIENGESELLSCHAFT GERMANY Wolfsburg DE2070000543 DE0007664039 28/05/1937 IFRS IFRS IFRS IFRS 173,320,402 169,866,478 141,486,262 114,920,054 10,408,570 21,311,069 15,838,789 7,683,377 WANT: Company name Country Region BvD ID number ISIN number Date of incorporation YEAR Accounting practice Operating revenue (Turnover) th GBP P/L before tax th GBP 1 BP P.L.C. UNITED KINGDOM London SW1Y GB00102498 GB0007980591 14/04/1909 2010 IFRS 197,310,000 -3,082,000 1 BP P.L.C. UNITED KINGDOM London SW1Y GB00102498 GB0007980591 14/04/1909 2011 IFRS 248,673,000 24,988,000 1 BP P.L.C. UNITED KINGDOM London SW1Y GB00102498 GB0007980591 14/04/1909 2012 IFRS 238,871,000 11,571,000 1 BP P.L.C. UNITED KINGDOM London SW1Y GB00102498 GB0007980591 14/04/1909 2013 IFRS 239,218,000 18,246,000 2 VOLKSWAGEN AKTIENGESELLSCHAFT GERMANY Wolfsburg DE2070000543 DE0007664039 28/05/1937 2010 IFRS 114,920,054 7,683,377 2 VOLKSWAGEN AKTIENGESELLSCHAFT GERMANY Wolfsburg DE2070000543 DE0007664039 28/05/1937 2011 IFRS 141,486,262 15,838,789 2 VOLKSWAGEN AKTIENGESELLSCHAFT GERMANY Wolfsburg DE2070000543 DE0007664039 28/05/1937 2012 IFRS 169,866,478 21,311,069 2 VOLKSWAGEN AKTIENGESELLSCHAF GERMANY Wolfsburg DE2070000543 DE0007664039 28/05/1937 2013 IFRS 173,320,402 10,408,570
... View more
03-18-2015
05:34 PM
Hello everybody, I need some help with transposing variables. More specifically, I use data for firms and various financial/accounting indicators. However, the database I use allows me to download the data in a specific form (see below, I tried to upload a file, but there was a message that the content of the file could not be uploaded, weird!!). For example, for interest paid, instead of having one column (variable) and get a value for each year, I get 11 different columns (for years 2005-2013). Company name Country Region Interest paid th GBP 2013 Interest paid th GBP 2012 Interest paid th GBP 2011 Interest paid th GBP 2010 Interest paid th GBP 2009 Interest paid th GBP 2008 Interest paid th GBP 2007 Interest paid th GBP 2006 Interest paid th GBP 2005 1. ROYAL DUTCH SHELL PLC UNITED KINGDOM London SE1 991.000 1.081.000 883.000 636.000 336.000 814.000 556.000 587.000 622.000 2. BP P.L.C. UNITED KINGDOM London SW1Y 645.000 692.000 802.000 747.000 687.000 1.067.000 557.000 367.000 359.000 3. VITOL HOLDING B.V. NETHERLANDS Rotterdam n.a. n.a. n.a. n.a. n.a. n.a. 202.317 170.755 41.437 4. VOLKSWAGEN AKTIENGESELLSCHAFT GERMANY Wolfsburg 1.981.388 2.128.766 1.713.093 1.831.572 2.017.465 1.732.703 1.210.215 1.063.182 1.048.908 5. TOTAL SA FRANCE Hauts-de-Seine 1.004.093 978.262 955.717 744.931 778.343 1.264.921 1.511.483 1.346.071 1.009.857 6. GLENCORE PLC UNITED KINGDOM Jersey 1.075.000 843.000 763.000 777.000 n.a. n.a. n.a. n.a. n.a. 7. GLENCORE INTERNATIONAL AG SWITZERLAND Zug n.a. 868.821 767.091 777.663 527.324 n.a. n.a. n.a. n.a. 8. E D F TRADING LIMITED UNITED KINGDOM London SW1E 41.000 38.000 29.000 21.000 38.000 42.000 12.000 16.000 2.000 9. E.ON RUHRGAS AUSTRIA GMBH AUSTRIA Wien n.a. 2.176.425 n.a. n.a. n.a. n.a. n.a. n.a. n.a. 10. E.ON SE GERMANY Düsseldorf 2.132.128 n.a. n.a. n.a. 1.017.628 2.913.613 1.459.312 1.484.164 1.221.557 What I want to do is have a date variable and then have a single column instead of 11 for each variable. I would appreciate it if anyone could help. Many thanks in advance.
... View more
02-26-2015
02:15 PM
Hello everyone, I have 50 time-series, for which I need to run a GARCH model for volatility forecasting. What I want to do is to avoid running each model seperately (red highlighted). Any ideas on how I could do that? Many thanks in advance. data data; infile "C:\Users\kg25\Desktop\Test Data.txt" dsd dlm='09'x firstobs=2 lrecl=32767 stopover; input date:ddmmyy. (a1-a50)(:numx.??); format date ddmmyy10.; run; *Create Returns and Squared Returns; data data2;set data; vars(*) a1--a50; array r(50); do i=1 to dim(vars); end; drop i; var(*) r1--r50; array rsq(50); do i=1 to dim(var); end; drop i; run; *create time variable; data data2;set data2(firstobs=2);time + 1; by date; run; *Choose in-sample; data data3;set data2(obs=1303); run; *Create observations for 1 year; data data4; do time = 1304 to 1564;output;end; run; *merge data; data data5; merge data3 data4;by time; run; *Estimate AR(1)-Garch (1,1) model; proc autoreg data=data5; model r1= / nlag=1 garch=(q=1, p=1) maxit=50 noprint; output out=data6 cev=vhat1; run; *merge data; data data7; merge data6 data2;by time; run; *Compute Mean Absolute Error and Root Mean Square Error; data data8;set data7(firstobs=1304); MAE=abs(rsq1-vhat1); RMSE=sqrt(rsq1-vhat1); run; proc means data=data8 mean stderr prt; var mae rmse; run;
... View more
10-02-2013
09:11 AM
Hello all, I am trying to convert a character date but what I am doing doesn't seem to work. I am attaching the file where date is of the form "1993-4" and the format is $6. I am using this code to convert it to yyq6. but it doesn't work: data want; set example; qtr=input(date,yyq6.); format qtr yyq6.; run; Any suggestions?
... View more