BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JJP1
Pyrite | Level 9

hi,
iam struggling to create output to get the current year,current month,previous_year,previous_month.
and iam using below code and iam not getting waht iam expecting please.kindly help
expected output should be
all the columns should be in numeric format and not character format

   proc sql;
      create view work.WXVDZU as
         select
            
            
           (year(today())) as Current_Year length = 8
               format = z2.
               informat = z2.,
            (month(today())) as Current_Month length = 8
               format = z2.
               informat = z2.,
            (%sysfunc(year(%sysfunc(intnx(month, %sysfunc(today()), -1))))) as Previous_Year length = 8
               format = z2.
               informat = z2.,
            (%sysfunc(month(%sysfunc(intnx(month, %sysfunc(today()), -1))))) as Previour_Month length = 8
               format = z2.
               informat = z2.
      from &etls_lastTable
      ;
   quit;;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

To simply create a dataset, use SAS' in-built Swiss Army Knife, aka The Data Step:

data wxvdzu;
length
  current_year
  current_month
  previous_year
  previous_month
    3
;
format
  current_year
  previous_year
    z4.
  current_month
  previous_month
    z2.
;
current_year = year(today());
current_month = month(today());
previous_year = year(intnx('month',today(),-1));
previous_month = month(intnx('month',today(),-1));
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Just to understand, all you want is a table with the current year, month, the previous year and the previous month?

JJP1
Pyrite | Level 9

yes @PeterClemmensen  .all i need  is with the current year, current month, the previous year and the previous month values with numeric columns.

also i need informat and format values also what to mention

as iam using this in SAS DI please

andreas_lds
Jade | Level 19

The view you are trying to create does not need any variable from "&etls_lastTable", right? Why do want to create a view at all?

 

 

SASKiwi
PROC Star

You only need %SYSFUNC if you are doing calculations on macro variables, and I see no macro variables at all. You can start by removing all uses of %SYSFUNC.

Kurt_Bremser
Super User

To simply create a dataset, use SAS' in-built Swiss Army Knife, aka The Data Step:

data wxvdzu;
length
  current_year
  current_month
  previous_year
  previous_month
    3
;
format
  current_year
  previous_year
    z4.
  current_month
  previous_month
    z2.
;
current_year = year(today());
current_month = month(today());
previous_year = year(intnx('month',today(),-1));
previous_month = month(intnx('month',today(),-1));
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 746 views
  • 1 like
  • 5 in conversation