Hi Everyone,
I have encountered a few problems on my data set and was wondering if anyone here may be able to help out by showing me or providing hints on the codes I need to run the following things.:
1). If I have 2 columns of data, with say 10000 but specifically want to regress between row 5000 to say 5899, what is the code for this?
proc reg
data = regresstest.dat;
model RE_RF = RM_RF - (what to I put here so I control which dates I include in the regression)
I will need to regress like this many times, so I really need a code to do this, and the regress the same variables with different rows of data included (each rows being a time period of course).
2). I have a dataset, where lets say there is 6 rows - 2 columns:
Date volume bought
20051221 5
20051221 3
20051222 8
20051222 9
20051224 5
20051225 4
There are 2 rows for the date 20051221 - Is there a code so that in any repeating dates - the corresponding (volume bought) is the sum of the volume bought on the ows with all the same dates?
Also there is no value for 20051223 - Is there a code to autofill a date 20051223 - and the put volume bought as 0. (My data set will have 1000s of rows so I can't do this manually.
Essentially I want the example above to look like this:
Date Volume bought
20051221 (5+3)
20051222 (8+9)
20051223 0
20051224 5
20051225 4
3). Lastly, if I had multiple data sets but each dataset and I want to SUM - Say dataset 1 - ROW 20 to 40, column 3, with dataset 1 - row 50 to 70 colume 3 with dataset 2, and so on, then I want the output in a new data file. Is there a code to achieve this.
THANK YOU SO MUCH FOR YOUR TIME - THANKS IN ADVANCE - I would appreciate it if you are able to help me out. THANK YOU EVERYONE AGAIN IN ADVANCE - I am in pretty desparate need for codes to do something like this.
I didn't read your entire post, just the part about only including certain records in a given analyses.
You could incorporate firstobs and obs into your code. It works the same for procs as it does for a datastep.
Thus, given sashelp.class, if you want the 3rd record and the four records that come after it, you could use:
%let start=3;
%let end=%eval(&start.+4);
data want;
set sashelp.class (firstobs=&start. obs=&end.);
run;
data have;
format hold_date date date9.;
input date mmddyy10. v_bought;
retain hold_date rownum;
if _n_=1 then do; hold_date=date; rownum=1; end;
if hold_date ne date and hold_date ne date+1 then do;
output;
rownum=rownum+1; date=hold_date+1; v_bought=0;
output;
end;
else output;
rownum=rownum+1;
hold_date=date;
keep date v_bought rownum;
cards;
05/01/2005 7
05/01/2005 2
05/01/2005 8
05/01/2005 1
05/01/2005 7
05/03/2005 6
05/03/2005 2
05/03/2005 4
05/03/2005 1
05/05/2005 4
05/05/2005 8
05/05/2005 8
05/05/2005 8
05/07/2005 8
05/07/2005 7
05/07/2005 5
05/07/2005 7
05/09/2005 9
05/09/2005 2
05/09/2005 2
05/09/2005 3
05/11/2005 4
05/11/2005 8
05/11/2005 1
05/11/2005 6
;
run;
proc sql;
create table want as
select date, sum(v_bought) as v_total
from have
group by date
order by date;
quit;
proc reg data=have(where=(10<=rownum<=25));
model date=v_bought;
run;
data have_more;
format hold_date date date9.;
input date mmddyy10. v_bought;
retain hold_date rownum;
if _n_=1 then do; hold_date=date; rownum=1; end;
if hold_date ne date and hold_date ne date+1 then do;
output;
rownum=rownum+1; date=hold_date+1; v_bought=0;
output;
end;
else output;
rownum=rownum+1;
hold_date=date;
keep date v_bought rownum;
cards;
05/12/2005 7
05/12/2005 5
05/12/2005 8
05/12/2005 6
05/12/2005 5
05/12/2005 9
05/12/2005 7
05/13/2005 5
05/13/2005 1
05/13/2005 6
05/13/2005 6
05/13/2005 5
05/13/2005 7
05/13/2005 4
05/15/2005 8
05/15/2005 5
05/15/2005 3
;
run;
proc sql;
create table want_more as
select date, sum(v_bought) as v_total
from ( select date, v_bought
from have
where 1<=rownum<=35
union
select date, v_bought
from have_more
where 1<=rownum<=20 )
group by date
order by date;
quit;
For 1) in your reg model ,there are RE_RF RM_RF , but in your data posted not include these two variable.
For 2)
For3) You 'd better post some sample data and output you want to be.
data temp; input date : yymmdd10. volumn; format date yymmddn8.; cards; 20051221 5 20051221 3 20051222 8 20051222 9 20051224 5 20051225 4 ; run; proc sort data=temp; by date; run; data want(keep=_date sum); set temp; by date; pre_date=lag(date); if date-pre_date gt 1 then do; do i=pre_date+1 to date-1; _date=i;sum=0;output; end; end; if first.date then sum=0; sum+volumn; if last.date then do;_date=date;output;end; format _date yymmddn8.; run;
Ksharp
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.