DATA Step, Macro, Functions and more

Why there are errors when running the data set?

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Why there are errors when running the data set?

[ Edited ]
Data sp;
infile " E:\Appmethod2016\SAS-1209\SP500.csv " dlm=',' firstobs=2;
input  date spopen sphigh splow spclose spvol spaclose;
format date yymmdd10.;
run;

Data mt;
infile " E:\Appmethod2016\SAS-1209\Moto.csv " dlm=',' firstobs=2;
input  date mtaopen mtahigh mtalow mtaclose mtavol mtaaclose;
format date yymmdd10.;
run;

data Stocks;
merge sp mt;
spret=100*(spaclose-lag1(spaclose))/lag1(spaclose);
mtret =100*(mtaclose-lag1(mtaclose))/lag1(mtaclose);
dow=weekday(date);
run;

proc means data= stocks mean median std skew kurt min max n maxdec=3;
var spret mtret;
run;

proc format;
value dowf
1='Sun'
2='Mon'
3='Tue'
4='Wed'
5='Thu'
6='Fri'
7='Sat';
run;

proc sort data = stocks out= a;
format dow dowf.;
by dow;
run;

proc means data = a mean median std skew kurt min max n maxdec=3;
by dow;
var spret mtret ;
run;

proc sgplot data= stocks noautolegend;
title 'S&P 500 Returns by Day of the Week';
format dow dowf.;
vbox spret / category=dow;
xaxis label=' ';
yaxis label='Return (%)' grid;
refline 0;
run;

proc sgplot data=stocks;
title 'S&P 500 and Motorola Daily Returns';
reg x=spret y=mtret;
ellipse x=spret y=mtret/ alpha =.01;
ellipse x=spret y=mtret/ alpha =.001;
xaxis label='S&P 500 Return (%)';
yaxis label='Motorola Return (%)';
run;

proc reg data =stocks;
model mtret= spret;

proc reg data =stocks;
model mtret=spret ;
run;


Accepted Solutions
Solution
‎12-14-2016 11:28 PM
Super User
Posts: 19,868

Re: Why there are errors when running the data set?

Posted in reply to karen8169

Specify an informat for the date. 

All errors are related to date variable. 

 

 

Informat date anydtdte.;

View solution in original post


All Replies
Super User
Posts: 19,868

Re: Why there are errors when running the data set?

Posted in reply to karen8169

Please include the log, especially the error you're receiving. 

Contributor
Posts: 43

Re: Why there are errors when running the data set?

I posted log.
Solution
‎12-14-2016 11:28 PM
Super User
Posts: 19,868

Re: Why there are errors when running the data set?

Posted in reply to karen8169

Specify an informat for the date. 

All errors are related to date variable. 

 

 

Informat date anydtdte.;

Super User
Posts: 11,343

Re: Why there are errors when running the data set?

Posted in reply to karen8169

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Your code references a CSV file. If the XLSX is supposed to be the CSV why? Excel can change the contents enough that even saving the XLSX to CSV can yield a different result. Attach the csv file directly.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 347 views
  • 1 like
  • 3 in conversation