Help using Base SAS procedures

Create dataset with today's date in the name

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 124
Accepted Solution

Create dataset with today's date in the name

Greetings all.  I'm trying to create an empty dataset with today's date, in date9 format at the beginning of the name, but I can't figure out how to do it.  Any help would be greatly appreciated.

%Let today = %sysfunc(date(),date9.);

data otbr."&today_otbr";

length DT_BILL $10.;

length CD_CYCLE BILL_COUNT 8.;

length AT_BILL 8.2.;

run;

----------------------------------------------------------------------------

WARNING: Apparent symbolic reference TODAY_OTBR not resolved.
7984  data otbr."&today_otbr";
           -----
           22
           201
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, /, ;,
              _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

7985      length DT_BILL $10.;
7986      length CD_CYCLE BILL_COUNT 8.;
7987      length AT_BILL 8.2.;
                         ---
                         352
                            -
                            22
                            200
ERROR 352-185: The length of numeric variables is 3-8.

ERROR 22-322: Syntax error, expecting one of the following: a name, ;, DEFAULT, _ALL_,
              _CHARACTER_, _CHAR_, _NUMERIC_.

ERROR 200-322: The symbol is not recognized and will be ignored.

7988  run;

ERROR: The value &TODAY_OTBR is not a valid SAS name.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



Accepted Solutions
Solution
‎09-12-2012 03:57 PM
Super Contributor
Posts: 1,636

Re: Create dataset with today's date in the name

dataset name can't starting with number.

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: Create dataset with today's date in the name

From what I can see,

1, you are missing a '.', Try adding it on:

2. Length statement can only take 3-8, not 8.2, that is for format, change that. Also, for numeric variables, the default length is 8, so you can skip all of your length statement.

%Let today = %sysfunc(date(),date9.);

data otbr._&today._otbr;

length DT_BILL $10.;

run;

Haikuo

Update:

3. You can NOT name your table starting with a number. Add something like '_' in front of it.

4. Using quote in data statement will causing error, it is completely unnecessary.

Super Contributor
Posts: 1,636

Re: Create dataset with today's date in the name

Haikuo,

Why did you use "" in "&today._otbr"?

Respected Advisor
Posts: 3,156

Re: Create dataset with today's date in the name

Right, I overlook that part. Quote is completely unnecessary. Will update my initial response.

Haikuo

Super Contributor
Posts: 1,636

Re: Create dataset with today's date in the name

I don't think is a good idea to use "today" as a macro variable.

%Let dsn = %sysfunc(date(),date9.);

data otbr._&dsn._otbr;

Super User
Posts: 5,518

Re: Create dataset with today's date in the name

On a side note, I would suggest you switch from DATE9 to YYMMDDN8.  If you are creating a series of data sets, consider what the names will look like.  If you use YYMMDDN8 then the alphabetical order will match the order by creation date.

Frequent Contributor
Posts: 124

Re: Create dataset with today's date in the name

Posted in reply to Astounding

I'm getting closer.

%Let today = %sysfunc(date(),date9.);

data otbr.&today._OTBR;

length DT_BILL $10.;

length CD_CYCLE BILL_COUNT AT_BILL 8.;

run;

This creates the table, but it is creating it in the work library, not otbr.  Also, the name is not how I think the macro variable is resolving.  In the log I see these lines...

8233  %Let today = %sysfunc(date(),date9.);

8234  data otbr.&today._OTBR;

NOTE: Line generated by the macro variable "TODAY".

1      otbr.12SEP2012_OTBR

That makes me think the dataset to be created will be named 12SEP2012_OTBR, and it will be created in the otbr library.  However, when the table is actually created, it is named Sep2012_otbr, and it is in the work library.  Any ideas?

Greg

Frequent Contributor
Posts: 124

Re: Create dataset with today's date in the name

In fact, I don't even need the variable.  This does the *exact* same thing...

data otbr.%sysfunc(date(),date9.)_otbr;

length DT_BILL $10.;

length CD_CYCLE BILL_COUNT AT_BILL 8.;

run;

Still putting it in my work library for some reason.

Solution
‎09-12-2012 03:57 PM
Super Contributor
Posts: 1,636

Re: Create dataset with today's date in the name

dataset name can't starting with number.

Frequent Contributor
Posts: 124

Re: Create dataset with today's date in the name

DOH!!!  I should have know that, since the same is true for SQL Server.  Thank you so much for that.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 2991 views
  • 3 likes
  • 4 in conversation