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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 5 replies
  • 487 views
  • 1 like
  • 5 in conversation