02-18-2025
Junyong
Pyrite | Level 9
Member since
10-26-2017
- 277 Posts
- 0 Likes Given
- 1 Solutions
- 20 Likes Received
-
Latest posts by Junyong
Subject Views Posted 310 02-17-2025 08:00 PM 325 02-04-2025 01:10 PM 1187 03-28-2023 07:35 PM 1226 03-28-2023 05:37 PM 1110 11-11-2022 09:56 PM 1652 11-09-2022 12:31 PM 1706 11-09-2022 02:12 AM 1055 11-07-2022 04:29 PM 992 11-04-2022 01:04 PM 1731 07-13-2022 08:47 PM -
Activity Feed for Junyong
- Posted How to Capture Part of Log as Macro Variable? on SAS Programming. 02-17-2025 08:00 PM
- Posted How to Escape Line Break in Long Code Line? on SAS Programming. 02-04-2025 01:10 PM
- Got a Like for In VIEWTABLE, How Can I Directly Go to Certain Observation?. 02-27-2024 04:47 AM
- Got a Like for Re: In VIEWTABLE, How Can I Directly Go to Certain Observation?. 02-27-2024 04:47 AM
- Posted Re: How to Prevent Resolution of Ampersand? on SAS Programming. 03-28-2023 07:35 PM
- Posted How to Prevent Resolution of Ampersand? on SAS Programming. 03-28-2023 05:37 PM
- Posted How to Italicize Just One Word in FOOTNOTE? on Graphics Programming. 11-11-2022 09:56 PM
- Posted Re: Applying Arrow Tips to SGPLOT Lines and Axes on Graphics Programming. 11-09-2022 12:31 PM
- Posted Applying Arrow Tips to SGPLOT Lines and Axes on Graphics Programming. 11-09-2022 02:12 AM
- Posted Displaying Values for Histograms on Graphics Programming. 11-07-2022 04:29 PM
- Posted SGPLOT VBAR XAXIS Label Interval? on Graphics Programming. 11-04-2022 01:04 PM
- Posted Reading Tab-Delimited Data with Spaces on SAS Programming. 07-13-2022 08:47 PM
- Posted FILENAME FTP PROMPT in SAS OnDemand on SAS Programming. 04-25-2022 10:46 AM
- Posted Re: What Unconditional Variance Does AUTOREG Use? on SAS Forecasting and Econometrics. 11-08-2021 11:10 AM
- Posted What Unconditional Variance Does AUTOREG Use? on SAS Forecasting and Econometrics. 11-02-2021 04:43 PM
- Posted What Unconditional Variance Does AUTOREG Use? on SAS Programming. 11-01-2021 07:33 PM
- Got a Like for DO Loop and INFILE FILEVAR Together. 10-09-2021 04:11 AM
- Posted DO Loop and INFILE FILEVAR Together on SAS Programming. 10-08-2021 03:51 PM
- Posted Re: Controlling INPUT Pointer With DLM or DLMSTR on SAS Programming. 10-07-2021 04:29 PM
- Posted Controlling INPUT Pointer With DLM or DLMSTR on SAS Programming. 10-07-2021 02:44 PM
-
My Liked Posts
Subject Likes Posted 1 11-01-2020 10:34 AM 1 10-31-2020 09:50 PM 1 10-08-2021 03:51 PM 2 02-05-2021 03:18 AM 1 10-15-2020 04:08 PM
02-17-2025
08:00 PM
Suppose I download a webpage via PROC HTTP. filename myfile 'myfile.htm';
proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile;
run; Successful downloading returns NOTE: 200 OK as follows: 1 filename myfile 'myfile.htm'; 2 3 proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile;
4 run;
NOTE: 200 OK
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.05 seconds
cpu time 0.00 seconds Instead, unsuccessful downloading returns NOTE: 429 O as follows: 1 filename myfile 'myfile.htm';
2
3 proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile;
4 run;
NOTE: 429 O
NOTE: PROCEDURE HTTP used (Total process time):
real time 0.05 seconds
cpu time 0.00 seconds Is there any easy way to extract the "200" or "429" as a macro variable? Though I can output the log and infile it with symputx as follows, I wonder if there are easier ways than this. filename myfile 'myfile.htm';
proc printto log='mylog.log';
run;
proc http url='https://www.macrotrends.net/stocks/charts/KO/cocacola/balance-sheet' out=myfile;
run;
proc printto;
run;
data _null_;
infile 'mylog.log' truncover;
input;
if scan(lag3(_infile_),3)='http' then call symputx('note',scan(_infile_,2));
run;
%put ¬e;
data _null_;
infile 'del mylog.log' pipe;
run; Thanks for any helpful suggestions.
... View more
02-04-2025
01:10 PM
It seems SAS Macro adds a space when there is a line break as follows: %let Sentence=The line break in this sentence
will leave a space.;
%put &Sentence; SAS prints the following output: 1 %let Sentence=The line break in this sentence
2 will leave a space.;
3
4 %put &Sentence;
The line break in this sentence will leave a space. Is there any way to avoid this spacing and let SAS print The line break in this sentencewill leave a space. instead? This is not a SAS example, but like % in LaTeX as follows: \documentclass{article}
\begin{document}
The line break in this sentence
will leave a space.
However, the line break in this sentence%
won't leave a space.
\end{document} Thanks for your help!
... View more
03-28-2023
07:35 PM
Thanks—I tend to code Command Prompt and pipe directly for readability. It seems that, according to your filevar suggestion, this ampersand resolution issue, unlike others, cannot be addressed by %str , %quote , or %superq families.
... View more
03-28-2023
05:37 PM
I have an Excel file S&P 500_230328.xlsx on my desktop and want to rename it as S&P 500_230329.xlsx via infile pipe as follows: data _null_;
infile "ren %sysget(USERPROFILE)\Desktop\""S%nrstr(&)P 500_%sysfunc(putn(%sysfunc(today()),yymmddn6.))"".xlsx ""S%nrstr(&)P 500_%sysfunc(putn(%sysfunc(today())+1,yymmddn6.))"".xlsx" pipe;
run; The problem arises because SAS considers &P as a macro expression. I tried both %str() and %nrstr() for the ampersands above but failed (it seems %superq() doesn't work as well); I cannot use single quotes because of the date changes. How can I prevent WARNING: Apparent symbolic reference P not resolved. in this case?
... View more
11-11-2022
09:56 PM
In the following sgplot , can I just italicize Yahoo Finance in footnote so that it can be Source: Yahoo Finance for example? Here is the working snippet. filename SNP500 url 'https://query1.finance.yahoo.com/v7/finance/download/%5EGSPC?period1=-1388534400&period2=1767225599';
proc import file=SNP500 dbms=csv replace out=SNP500;
run;
ods results=off;
ods listing gpath='!USERPROFILE\Desktop\';
ods graphics/reset imagename='SNP500';
title 'S&P 500 Index';
footnote 'Source: Yahoo Finance';
proc sgplot;
series x=date y=close;
yaxis type=log;
run; Thanks for your help!
... View more
11-09-2022
12:31 PM
Does xaxis or yaxis have something similar to arrowheadpos for series ? I want to apply the arrow tips for axes per se as follows: Many thanks for your help again.
... View more
11-09-2022
02:12 AM
Excel lines (blue) and axes (gray) can easily introduce arrow tips as follows: I tried to do this in SGPLOT but couldn't find LINEATTRS or something for these arrow tips. Are the arrow tips above also available for SGPLOT SERIES and axes? Here is a sample snippet. data work;
do x=1 to 10;
y+rannor(1);
output;
end;
run;
ods results=off;
ods listing gpath='!userprofile\desktop';
ods graphics/reset noborder imagename='versionsas';
proc sgplot;
series x=x y=y;
run; Thanks for your help!
... View more
11-07-2022
04:29 PM
The following histogram uses the year labels of observations: Can I do something similar to this in SAS? Here is a non-labeled replication using SGPLOT HISTOGRAM. Here I attach the snippet; in addition, I also wonder if the vertical bars can be drawn not centered around tick marks but in between two tick marks. filename raw url 'https://query1.finance.yahoo.com/v7/finance/download/%5EGSPC?period1=-9999999999&period2=99999999999';
proc import file=raw dbms=csv replace out=raw;
run;
data return;
set raw;
year=year(date);
data return;
set return;
by year;
if last.year;
return=adj_close/lag(adj_close)-1;
run;
ods results=off;
ods listing gpath='!userprofile\desktop';
ods graphics/reset noborder imagename='Example';
proc sgplot;
where 1926<=year<=2017;
histogram return/binstart=-.8 binwidth=.1 nbins=17 scale=count;
xaxis values=(-.8 to .9 by .1) label='Return';
run; Thanks for your help!
... View more
11-04-2022
01:04 PM
SGPLOT VBAR is drawing all the 50 bars needed, but can I just apply label intervals to the x-axis below so that it changes from 1, 2, 3, …, 48, 49, 50 to 5, 10, 15, …, 40, 45, 50, for example? data SAMPLE;
call streaminit(1);
do X=1 to 50;
do ITERATION=1 to 50;
Y=rand('normal',X,X);
output;
end;
end;
run;
ods results=off;
ods listing gpath='!userprofile\desktop\';
ods graphics/reset imagename='SGPLOT';
proc sgplot;
vbar X/response=Y stat=mean limits=both;
run; Thanks for your help!
... View more
07-13-2022
08:47 PM
The following data have both tabs (delimiters) and spaces (not delimiters). I tried EXPANDTABS with a colon in INPUT as follows: data international_stock_exchanges;
infile cards expandtabs truncover;
input EXCHGCD EXCHGDESC :$80. Country $80.;
cards;
0 Subsidiary/Private Canada
0 Subsidiary/Private United States
1 Non-traded Company or Security Canada
1 Non-traded Company or Security Germany
1 Non-traded Company or Security Switzerland
1 Non-traded Company or Security Taiwan
1 Non-traded Company or Security United States
2 Consolidated Parent or Tracking Stock Company United States
3 Leveraged Buyout United States
4 Additional Company Record-PreSFAS 94, ProForma, PreAmended United States
; However, this colon made the second variable EXCHGDESC skip also at spaces as well as tabs as follows: How can I correctly use these tabs and spaces as delimiters and strings, respectively?
... View more
04-25-2022
10:46 AM
I was uploading a file via FTP using the following code: %put %sysfunc(dlgcdir(!userprofile\desktop));
filename original 'original.txt';
filename copy ftp 'copy.txt' host='my.address.com' user='myusername' prompt passive debug;
data _null_;
infile original;
input;
file copy;
put _infile_;
run; And I found that the PROMPT above is impossible in SAS OnDemand; I checked that only PASS works there. Is the PWENCODE-PASS combination the only way in SAS OnDemand? Or is there any other way to keep PROMPT here?
... View more
11-08-2021
11:10 AM
So it seems ε02=OLS MSE and h0=(ARCH0+ARCH1*MSE)/(1-GARCH0) in autoreg . %let url=https://query1.finance.yahoo.com/v7/finance/download/mcd;
%let period1=%sysevalf('5jul1966:0:0:0'dt-3653*24*60*60);
%let period2=%sysevalf('1nov2021:23:59:59'dt-3653*24*60*60);
filename mcd url "&url?period1=&period1%str(&)period2=&period2";
proc import file=mcd dbms=csv replace out=mcd;
run;
proc expand out=mcd;
id date;
convert adj_close=return/tout=(pctdif);
run;
ods select none;
ods results=off;
proc autoreg;
model return=/garch=(q=1,p=1);
output ht=variance out=mcd;
ods output fitsummary=fit parameterestimates=para;
run;
ods results=on;
ods select all;
data _null_;
set fit;
if _n_=2 then call symput('mse',nvalue1);
run;
data _null_;
set para;
if _n_=3 then call symput('arch0',estimate);
else if _n_=4 then call symput('arch1',estimate);
else if _n_=5 then call symput('garch1',estimate);
run;
data _null_;
set mcd;
if _n_=2 then call symput('variance',variance);
run;
%put %sysevalf((&arch0+&arch1*&mse)/(1-&garch1));
%put &variance; (1) Is there a reference for the formulation used for h0? (2) Is this stated in the guide?
... View more
11-02-2021
04:43 PM
The current post relocates the previous post. The following code (1) downloads McDonald's stock prices from July 5, 1966 to November 1, 2021, (2) computes its percent returns, and (3) estimates the GARCH(1,1) model. /*-----------------------------------------------------------------------------+
| set filename using url=ticker, period1=start, period2=end |
+-----------------------------------------------------------------------------*/
%let url=https://query1.finance.yahoo.com/v7/finance/download/mcd;
%let period1=%sysevalf('5jul1966:0:0:0'dt-3653*24*60*60);
%let period2=%sysevalf('1nov2021:23:59:59'dt-3653*24*60*60);
filename mcd url "&url?period1=&period1%str(&)period2=&period2";
/*-----------------------------------------------------------------------------+
| download daily mcdonalds data from yahoo |
+-----------------------------------------------------------------------------*/
proc import file=mcd dbms=csv replace out=mcd;
run;
/*-----------------------------------------------------------------------------+
| compute returns using prices |
+-----------------------------------------------------------------------------*/
proc expand out=mcd;
id date;
convert adj_close=return/tout=(pctdif);
run;
/*-----------------------------------------------------------------------------+
| run garch(1,1) using autoreg |
+------------------------------------------------------------------------------+
| the results are r(t)=0.0832+e(t) and |
| h(t)=0.009160+0.0485*e(t)^2+0.9539*h(t-1) |
| as ARCH1+GARCH1=0.0485+0.9539=1.0024>1, there is no unconditional variance |
+------------------------------------------------------------------------------+
| however, sas assigns h(1)=3.8592544106 to the jul 6, 1966 observation |
| where does this number come from? this is not ARCH0/(1-ARCH1-GARCH1)! |
+-----------------------------------------------------------------------------*/
proc autoreg;
model return=/garch=(q=1,p=1);
output ht=variance out=mcd;
run; Because ARCH1+GARCH1=0.0485+0.9539=1.0024>1, the unconditional variance is undefined. However, the output data set assigns 3.8592488163 as the variance of the first observation—how does AUTOREG compute this value of 3.8592488163 here? It seems this is not documented in The AUTOREG Procedure.
... View more
11-01-2021
07:33 PM
The following code (1) downloads McDonald's stock prices from July 5, 1966 to November 1, 2021, (2) computes its percent returns, and (3) estimates the GARCH(1,1) model. filename mcd url 'https://query1.finance.yahoo.com/v7/finance/download/
mcd?period1=-999999999&period2=9999999999';
proc import file=mcd dbms=csv replace out=mcd;
run;
proc expand out=mcd;
id date;
convert adj_close=return/tout=(pctdif);
run;
proc autoreg;
model return=/garch=(q=1,p=1);
output ht=variance out=mcd;
run; Because ARCH1+GARCH1=0.0485+0.9539=1.0024>1, the unconditional variance is undefined. However, the output data set assigns 3.8592488163 as the variance of the first observation—how does AUTOREG compute this value of 3.8592488163 here? It seems this is not documented in The AUTOREG Procedure.
... View more
10-08-2021
03:51 PM
1 Like
A SAS Communities page can be easily read as follows: data page(compress=char);
do i=1 to 1;
address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
infile dummy url filevar=address truncover end=j;
do until(j);
input page $32767.;
output;
end;
end;
run; However, the code becomes incorrect if I change DO I=1 TO 1; to DO I=1 TO 10; instead. data page(compress=char);
do i=1 to 10;
address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
infile dummy url filevar=address truncover end=j;
do until(j);
input page $32767.;
output;
end;
end;
run; Can't I repeat INFILE FILEVAR inside DO loops? Though I know that the following code works correctly, I want to know where I'm misunderstanding. data page;
do i=1 to 10;
output;
end;
run;
data page(compress=char);
set page;
address=cats("https://communities.sas.com/t5/forums/recentpostspage/post-type/thread/page/",i);
infile dummy url filevar=address truncover end=j;
do until(j);
input page $32767.;
output;
end;
run; Thanks.
... View more