Hello community,
I want plot data using proc timeseries
proc timeseries data=data plots= series; id date interval=YEAR; var Debt; run;
but i didn't get the diagram.
Thank you for your helps.
@dw_sas was right in his suggestion of how to fix your problem.
But you still have a few issues in your code.
data data;
set data;
%let start=1983;
%let end=2017;
data data;
set data;
format date year4. ;
date = "01jan&start."d;
do until (date > "01jan&end."d);
output data;
date = intnx('year',date,1);
end;
run;
I changed the variable name from date to myDate to make the code more clear.
See below:
If the suggestions you got in https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Error-in-date-variable/m-p/492797 did not provide the necessary solution, please provide example data in usable form (datastep with datalines), and describe what you want to get out of it (and/or show an example for that). It might be that proc timeseries is not what you need at all.
When i want plot data i get error that the variable date is not defined.
After resolving the first problem thanks to you and i want plot data with that code i got only this table.
This is the data
Please revise your question. Provide test data in the form of a datastep:
only need a few rows which accurately describe the problem.
Next post the exact code you are using - use the code window, it is the {i} above post area, to retain formatting.
Next post the log of the run part in question, again use the code window.
A quick glance at the Excel file you posted, shows that there is no variable called date, therefore you get the error because you have tried to use a variable which is not in the data in:
id date interval=YEAR;
^here
I would also advice you stop using SAS keywords as names, data=data for instance is just bad coding, and calling a date variable date, will just get very confusing.
The date variable in excel is named Year. When i want plot the data using this variable i got the message:
"ERROR: Duplicate time interval found at observation number 2 in the data set WORK.DATA, according to
the INTERVAL=YEAR option and the ID variable values. The current ID is Year=1984 and the
previous is Year=1983, which are within the same YEAR interval.
Check that INTERVAL=YEAR is correct for this data set, and that the ID variable Year contains
SAS date or datetime values that correctly identify the observations"
So i created new variable date named date using code in ancient post and i used the code to plot data i got
"ERROR: The data set WORK.DATA is not sorted by the ID variable. At observation number 36, date=1983,
but date=2017 for the previous observation."
I sorted the variable by date but when i used code to plot it i got
"ERROR: Observation with duplicate ID value found. The value of the ID variable, date=1983, at
observation number 2 in data set WORK.DATA is the same as the previous observation."
Please show your full code and log.
@Lok07 wrote:
The date variable in excel is named Year. When i want plot the data using this variable i got the message:
"ERROR: Duplicate time interval found at observation number 2 in the data set WORK.DATA, according to
the INTERVAL=YEAR option and the ID variable values. The current ID is Year=1984 and the
previous is Year=1983, which are within the same YEAR interval.
Check that INTERVAL=YEAR is correct for this data set, and that the ID variable Year contains
SAS date or datetime values that correctly identify the observations"So i created new variable date named date using code in ancient post and i used the code to plot data i got
"ERROR: The data set WORK.DATA is not sorted by the ID variable. At observation number 36, date=1983,
but date=2017 for the previous observation."I sorted the variable by date but when i used code to plot it i got
"ERROR: Observation with duplicate ID value found. The value of the ID variable, date=1983, at
observation number 2 in data set WORK.DATA is the same as the previous observation."
this is the code
proc import out=data datafile="C:\Users\hp\Desktop\debt.xlsx" dbms=excel replace; getnames=yes; run; proc timeseries data=data plots= series; id Year interval=YEAR; var Debt; run; %let start=1983; %let end=2017; data data; set data; format date year4. ; date = "01jan&start."d; do until (date > "01jan&end."d); output data; date = intnx('year',date,1); end; run; proc sort data=data; by date; run; proc timeseries data=data plots= series; id date interval=YEAR; var Debt; run;
Hello,
In order to better understand the source of the problem you are encountering, please provide the following information:
1) The "Alphabetic List of Variables and Attributes" table from the output of PROC CONTENTS run on your data set, DATA
2) Output of PROC PRINT on the first 10 observations of your data set, DATA
3) Details on what you are trying to plot--daily or annual data. The Excel file contains daily data, but you are specifying INTERVAL=YEAR in the ID statement of PROC TIMESERIES. Are you trying to accumulate the daily data to annual data prior to plotting it? If so, then how do you want to accumulate the data (ie. annual totals, averages, etc.)?
The first two steps can be accomplished with the following code:
proc contents data=work.data;
run;
proc print data=work.data(obs=10);
run;
Once we have this information, we will be better able to address your question.
Thanks,
DW
I want to plot annual data.
When i created a new variable date the format of this variable is YEAR4.
Please show your full code and log.
Code
proc import out=data datafile="C:\Users\hp\Desktop\debt.xlsx" dbms=excel replace; getnames=yes; run;
proc timeseries data=data plots= series; id Year interval=YEAR; var Debt; run; %let start=1983; %let end=2017; data data; set data; format date year4. ; date = "01jan&start."d; do until (date > "01jan&end."d); output data; date = intnx('year',date,1); end; run; proc sort data=data; by date; run; proc timeseries data=data plots= series; id date interval=YEAR; var Debt; run;
Hi,
After you import your annual data, the YEAR variable is a simple numeric year. PROC TIMESERIES expects the ID variable to be a SAS date or datetime variable. To create a SAS date variable from your numeric YEAR variable, please run the following code immediately after your PROC IMPORT step. The MDY function will create a SAS date variable aligned to January 1 of each year in your YEAR variable. Once you have this new DATE variable, you can use it in the ID statement in PROC TIMESERIES:
data debt_data;
set data;
date=mdy(1,1,year);
format date year4.;
run;
proc timeseries data=debt_data plots= series;
id date interval=YEAR;
var Debt;
run;
I hope this helps!
DW
i got the same problem without diagram
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.