BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
aarnold18
Calcite | Level 5

Hello,

 

I am trying to create a table with the timestamp name Member_YYYYMMDDHHSS using proc sql. 

 

Does anyone know how to insert that into the table name?

 

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@aarnold18 wrote:

Thanks, changing the single quotes to double got the file to export with the macro properly running. 

 

However, it isn't in the CSV format now. it just exports as "file" Any ideas? 

 

proc export data=Member
outfile="......../Member_&date"
dbms=csv
replace;
run;


Huh?  If you wrote a CSV file it IS a CSV file.  Just look at it with any text editor.

I suspect you are talking about the fact that you did not NAME the file with an extension of .csv.

outfile="......../Member_&date..csv"

Note the extra period.  The first one will be used by the macro processor to indicate where the name of the macro variable ends so you need the second one so it will be part of the actual name.

 

PS Don't let EXCEL open your CSV without double checking that it hasn't converted character strings to numbers (or worse thought they were date strings) and changed the values.

View solution in original post

6 REPLIES 6
ballardw
Super User

First, are you sure that you want to use 12 of the available 32 characters to name a SAS data set for this?

 

And exactly how are you envisioning "proc sql" comes into this? The syntax for naming a data set doesn't change in SQL so I wonder if you have something odd in mind.

aarnold18
Calcite | Level 5

Hi Ballard,

 

Well the table name itself doesn't have to have the timestamp. However the exported table name does. 

 

Currently I have the date format figured out:

%let now=%sysfunc(datetime());
%let date=%sysfunc(putn(&now,B8601DN8))%sysfunc(timepart(&now),B8601TM6);

 

 

However when I use this export function, the filename gets exported as Member_&date and not with the actual digits in the name.

 

proc export data=Member
outfile='........../Member_&date..csv'
dbms=csv
replace;
run;

 

So I guess I need my proc export function adjusted

Tom
Super User Tom
Super User

The macro processor does not process string literals that are bounded by single quotes.

Use double quotes instead if you want the macro processor to act on the value of the string.

aarnold18
Calcite | Level 5

Thanks, changing the single quotes to double got the file to export with the macro properly running. 

 

However, it isn't in the CSV format now. it just exports as "file" Any ideas? 

 

proc export data=Member
outfile="......../Member_&date"
dbms=csv
replace;
run;

Tom
Super User Tom
Super User

@aarnold18 wrote:

Thanks, changing the single quotes to double got the file to export with the macro properly running. 

 

However, it isn't in the CSV format now. it just exports as "file" Any ideas? 

 

proc export data=Member
outfile="......../Member_&date"
dbms=csv
replace;
run;


Huh?  If you wrote a CSV file it IS a CSV file.  Just look at it with any text editor.

I suspect you are talking about the fact that you did not NAME the file with an extension of .csv.

outfile="......../Member_&date..csv"

Note the extra period.  The first one will be used by the macro processor to indicate where the name of the macro variable ends so you need the second one so it will be part of the actual name.

 

PS Don't let EXCEL open your CSV without double checking that it hasn't converted character strings to numbers (or worse thought they were date strings) and changed the values.

Tom
Super User Tom
Super User

I suspect you will want to also include 2 digits for the minutes.

SQL does not have anything to do with this since it just runs the code you give it.  You will need to use some code generation.  The macro processor is good at that.

Do you have particular timestamp you want to use? You can use the DATETIME() function to get the current clock time.  Use the B8601DT format to make string of digits with the letter T between the date and the time of day parts.  If you don't want the T use COMPRESS() to remove it.

%let ts=%sysfunc(compress(%sysfunc(datetime(),b8601dt15.),T));

data want_&ts ;
  set sashelp.class;
run;

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!

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
  • 6 replies
  • 490 views
  • 2 likes
  • 3 in conversation