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

I thought we cannot use the "-"( hyphen) in  the dataset name. We got this kind of name for a dataset from a vendor.  I try to do some analysis to using the set statement. But I am not sure  how to do it, my SET statements not working because of the symbol, is there a way I can create  copy of this data into sas session to work on it. I am not really sure How they able to create the SAS dataset.( is there a way?). The following how the name looks like. Thank you.

libname account 'c:\temp\act';
data expenses;
   set account. ny_2022-dec_accounts;*dataset name in library "-" after the 2022;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Copy to work library then.

 

 

options msglevel=i;

filename src 'c:\document\ny\ny_2022-dec_accounts.sas7bdat' recfm=n;
filename dest "%sysfunc(pathname(work))/ny_dec2022_accounts.sas7bdat" recfm=n;

data _null_;
   length msg $ 384;
   rc=fcopy('src', 'dest');
   if rc=0 then
      put 'Copied SRC to DEST.';
   else do;
      msg=sysmsg();
      put rc= msg=;
   end;
run;

data expenses;
   set ny_dec2022_accounts;
run;

View solution in original post

17 REPLIES 17
SASKiwi
PROC Star

Try this:

libname account 'c:\temp\act';
data expenses;
   set account.'ny_2022-dec_accounts'n;*dataset name in library "-" after the 2022;
run;

The dataset may have been created the same way I've suggested reading it.

SASuserlot
Barite | Level 11

@SASKiwi  Thank you. Unfortunately no luck I am getting 'Invalid data set name error'

SASKiwi
PROC Star

OK, try this then - it should allow the hyphen.

options VALIDMEMNAME = EXTEND;
libname account 'c:\temp\act';
data expenses;
   set account.'ny_2022-dec_accounts'n;*dataset name in library "-" after the 2022;
run;
SASuserlot
Barite | Level 11

 Didn't worked . Still same issue 'Invalid data set name'. And I got the following note but it did not allowing me. I am using SAS 9.4 windows .

SASuserlot_0-1669176586493.pngSASuserlot_1-1669176611680.png

 

SASKiwi
PROC Star

Can you please post your complete SAS log including your code and any notes and errors. Please do it as a copy and paste NOT a screenshot.

SASuserlot
Barite | Level 11

 


1    options VALIDMEMNAME=EXTEND ;
NOTE: Windowing environment support for VALIDMEMNAME=EXTEND is limited to Editor, Log, and Output windows.
2    *create library;
3
4    libname account 'c:\document\ny';
NOTE: Libref ACCOUNT was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\document\ny
5
6    * data set creation;
7
8    data expenses;
9       set account.'ny_2022-dec_accounts'n;*dataset name in library "-" after the 2022;
           -------------------------------
            211
ERROR 211-185: Invalid data set name.

10   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.EXPENSES may be incomplete.  When this step was stopped there were 0 observations
         and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds 

 Here is my log. sorry for the inconvenience. I tried with out using " 'n " and single quotations too. but no luck. Thank you for your time.

SASuserlot
Barite | Level 11

Thanks, @Kurt_Bremser .  can you please provide me with an example? ( I don't want to change the original file name). By any chance your referring 'RENAME'  like this?

SASuserlot_0-1669183862496.png

 

Source: https://documentation.sas.com/doc/en/sclref/9.4/p0mgkyalwbgx2cn18e8z05b90s5v.htm#n1gufiu0rf7qv2n1v05...

Kurt_Bremser
Super User

No. OS means Operating System.

Since you work on Windows, you would either use the Windows Explorer or the ren command in a cmd window.

Or, if the XCMD system option is enabled in SAS, you could use the ren command in an X statement or an INFILE PIPE.

data _null_;
infile pipe "ren c:\temp\act\ny_2022-dec_accounts.sas7bdat c:\temp\act\ny_2022_dec_accounts.sas7bdat 2>&1";
input;
put _infile_;
run;
SASuserlot
Barite | Level 11

I tried using your code. Unfortunately it didn't work  . Can you please correct me, if I am doing anything wrong ( Note: I didn't want to change the original file name, I just want to read into SAS so that I can do analysis). Thank you


1
2    options noxwait ;
3    data _null_;
4    infile pipe "ren
4  ! c:\document\ny\ny_2022-dec_accounts.sas7bdat
4  ! c:\document\ny\ny_2022_dec_accounts.sas7bdat 2>&1";
      --------------------------------------------------
      23

ERROR 23-2: Invalid option name "ren
             c:\document\ny\ny_2022-dec_accounts.sas7bdat
             c:\document\ny\ny_2022_dec_accounts.sas7bdat
             2>&1".

5    input;
6    put _infile_;
7    run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.XX may be incomplete.  When this step was stopped there were 0 observations and 0
         variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.00 seconds
Reeza
Super User

Does the name have a space at the front? 

 

Rules for EXTEND Are

  • can be up to 32 bytes in length.
  • can contain special characters except for / \ * ? " < > | : -. A name that contains special characters must be specified as a name literal.
  • cannot begin with a blank or a period.
  • ignores leading and trailing blanks.
  • can contain mixed-case letters. SAS internally converts the member name to uppercase. Therefore, you cannot use the same member name with a different combination of uppercase and lowercase letters to represent different variables. For example, cat, Cat, and CAT all represent the same member name. (footnote 1)

That being said, I get an error every time I try to create a data set with that name so it's invalid. You will have to rename it, I suggest copying it first and then renaming it.

 

 69         libname account '/home/fkhurshed/Demo1/';
 NOTE: Libref ACCOUNT was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /home/fkhurshed/Demo1
 70         
 71         data account.'ny_2022-dec_accounts'n;
 72         set sashelp.class;
 73         run;
 
 ERROR: The value 'NY_2022-DEC_ACCOUNTS'n is not a valid SAS member name.
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              474.09k
       OS Memory           24224.00k
       Timestamp           11/23/2022 03:52:19 PM
       Step Count                        48  Switch Count  0
       Page Faults                       0
       Page Reclaims                     70
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           8
       

 If you're concerned about traceability in the code, you can use FCOPY to copy/rename the file.

 

options msglevel=i;

filename src '/home/fkhurshed/Demo1/ny_2022-dec_accounts.sas7bdat' recfm=n;
filename dest '/home/fkhurshed/Demo1/ny_dec2022_accounts.sas7bdat' recfm=n;

data _null_;
   length msg $ 384;
   rc=fcopy('src', 'dest');
   if rc=0 then
      put 'Copied SRC to DEST.';
   else do;
      msg=sysmsg();
      put rc= msg=;
   end;
run;

data expenses;
   set account.ny_dec2022_accounts;
run;

 

SASuserlot
Barite | Level 11

Thanks @Reeza . I don't have any blank spaces in the name.  If I don't have any option, your solution is the option and inform my upper level. Since they don't  give me the access to copy/ rename or do any thing  in the folder access.  I thought we can not use any fancy character in name. At least  from this post I learned about EXTEND option.

Reeza
Super User

Copy to work library then.

 

 

options msglevel=i;

filename src 'c:\document\ny\ny_2022-dec_accounts.sas7bdat' recfm=n;
filename dest "%sysfunc(pathname(work))/ny_dec2022_accounts.sas7bdat" recfm=n;

data _null_;
   length msg $ 384;
   rc=fcopy('src', 'dest');
   if rc=0 then
      put 'Copied SRC to DEST.';
   else do;
      msg=sysmsg();
      put rc= msg=;
   end;
run;

data expenses;
   set ny_dec2022_accounts;
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
  • 17 replies
  • 1214 views
  • 5 likes
  • 5 in conversation