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;
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;
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.
@SASKiwi Thank you. Unfortunately no luck I am getting 'Invalid data set name error'
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;
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 .
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.
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.
Rename the .sas7bdat file on the OS level.
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?
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;
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
Change the order of the INFILE statement:
infile "ren c:\temp\act\ny_2022-dec_accounts.sas7bdat c:\temp\act\ny_2022_dec_accounts.sas7bdat 2>&1" pipe;
Does the name have a space at the front?
Rules for EXTEND Are
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;
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.