BookmarkSubscribeRSS Feed
SystemsasdD2019
Calcite | Level 5
please , I want to change format  my data,  monthly,I Imprt it from stata program ,  start from 2016m1  ,   2016m2  ,   2016m3     .....   . to 2019m12 . ,It is     48 value , the date variable  name,  "month"    the data is gold price and silver price my application on VARMAX on SAS on deamond academic . I  need your help . with many thanks ,
 
18 REPLIES 18
PaigeMiller
Diamond | Level 26

It would help us greatly if you could format your question in a readable way.

 

You also say you want to change the format of your data, but you don't show any data and you don't say what the end result should be. We need to know these things in order to be able to assist.

--
Paige Miller
Reeza
Super User
Please show what you have as input, what you want as output and anything you've tried so far. Please post your data using the code blocks and use full sentences whenever possible.
PGStats
Opal | Level 21

As far as I know, SAS doesn't provide an informat to read such fields directly. If you are looking for a way to read dates in the YYYYmMM format, you would have to use something like:

 

data have;
str = "2019m2";
date = input (cats(translate(str,"-","m"),"-1"), yymmdd10.);
format date yymmdd10.;
run;

proc print; run;
PG
Kurt_Bremser
Super User

If I interpret your (very confusing) post correctly, you should look at this:

data have;
input inmonth $7.;
datalines;
2016m1
2016m2
2019m12
;

data want;
set have;
outmonth = input(compress(inmonth,'m'),yymmn6.);
format outmonth yymm7.;
run;
SystemsasdD2019
Calcite | Level 5
thank you for your answar , I have implemented the program and the result is shown below , 


data have;
input inmonth $7.;
datalines;
2016m1
2016m2
2016m3
2016m4
2016m5
2016m6
2016m7
2016m8
2016m9
2016m10
2016m11
2016m12
2017m1
2017m2
2017m3
2017m4
2017m5
2017m6
2017m7
2017m8
2017m9
2017m10
2017m11
2017m12
2018m1
2018m2
2018m3
2018m4
2018m5
2018m6
2018m7
2018m8
2018m9
2018m10
2018m11
2018m12
2019m1
2019m2
2019m3
2019m4
2019m5
2019m6
2019m7
2019m8
2019m9
2019m10
2019m11
2019m12
;

data want;
set have;
outmonth = input(compress(inmonth,'m'),yymmn6.);
format outmonth yymm7.;
run;

but when I implemented the program :
PROC VARMAX DATA=WORK.IMPORT PRINTALL PLOTS=ALL;
MODEL LSILVERPRICE LGOLDPRICE/DIF=(LSILVERPRICE(1) LGOLDPRICE(1)) Q=1 METHOD=ML;
OUTPUT LEAD=25;
ID MONTH INTERVAL=MONTH;
RUN;



An error appears :
ERROR : Variable month in list does not match type prescribd for this list  
Kurt_Bremser
Super User

I guess that your variable month is of type character.

From the documentation of the VARMAX Procedure:

 

The ID statement specifies a variable that identifies observations in the input data set. The datetime variable specified in the ID statement is included in the OUT= data set if the OUTPUT statement is specified. The ID variable is usually a SAS datetime variable. The values of the ID variable are extrapolated for the forecast observations based on the value of the INTERVAL= option.

 

(emphasis by me)

 

The ID variable should therefore be numeric; it might be that a date value will also work, but to be sure, you should convert it to a datetime value (count of seconds from 1960-01-01T00:00:00)

Note that my code creates outmonth as a numeric date variable, which can be converted to datetime by using

dhms(outmonth,0,0,0)

 

SystemsasdD2019
Calcite | Level 5

Sorry , I am a beginner in the SAS program  , so how do I implement the conversion from numerical to datetime sas.

PGStats
Opal | Level 21

Change your program to:

 

data want;
set have;
outmonth = dhms(input(compress(inmonth,'m'),yymmn6.), 0,0,0);
format outmonth datetime.;
run;
PG
SystemsasdD2019
Calcite | Level 5

thank you very mach for your answer , but when I implement the program 

 

PROC VARMAX DATA=WORK.IMPORT PRINTALL PLOTS=ALL;
MODEL LSILVERPRICE LGOLDPRICE/DIF=(LSILVERPRICE(1) LGOLDPRICE(1)) Q=1 METHOD=ML;
OUTPUT LEAD=25;
ID outmonth INTERVAL=month;
RUN;

An error appears :
ERROR: Variable outmonth not found .
Kurt_Bremser
Super User

You need to adapt the code to your data. Use variables that exist in your dataset. If you created outmonth in a new dataset, use this dataset in the varmax procedure.

SystemsasdD2019
Calcite | Level 5

Sory , when I implement this program :An error apear 

proc varmax data=WORK.WANT plot(unpack)=(residual model forecasts);
id OUTMONTH interval=month;
model Lsilverprice Lgoldprice / dify=(1,12) noint p=0 q=1;
output lead=12;
run;

 An ERROR : variable Lsilverprice not found 

      ERROR variable Lgoldprice not found 

 

 

I refer to data set of variable of date  OUTMONTH  but the dataset of variabls Lsilverprice Lgoldprice is WORK.IMPORT . how can do my code with many thanks .

SystemsasdD2019
Calcite | Level 5

Sory, But the procedure requires the use of all variables Lsilverprice Lgoldprice  and variable of date OUTMONTH .there is no way to combine them , when I apply the program :

title "Illustration of ODS Graphics";
proc varmax data=WANT plot(unpack)=(residual model forecasts);
id OUTMONTH interval=month;
model Lsilverprice Lgoldprice / dify=(1,12) noint p=0 q=1;
output lead=12;
run;

 appears an ERROR: variable Lsilverprice not found 

                    ERROR variable Lgoldprice not found 

 

 

when I apply the program ;

 

title "Illustration of ODS Graphics";
proc varmax data=IMPORT   plot(unpack)=(residual model forecasts);
id OUTMONTH interval=month;
model Lsilverprice Lgoldprice / dify=(1,12) noint p=0 q=1;
output lead=12;
run;

 

An error appears:

 ERROR : variable OUTMONTH not found

 

there is no way to combine them , with  thanks and appreciation .

Kurt_Bremser
Super User

KNOW

YOUR

DATA

 

You have to know which variables are present in your dataset, and subsequently which ones to use in the procedure, according to the documentation. We could only try to provide further help if you give us a usable example of your dataset in a data step with datalines and what information you want to gain by using the varmax procedure.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 18 replies
  • 1804 views
  • 0 likes
  • 5 in conversation