Librefs are restricted to eight characters ошибка sas
At the outset, I would like to apologize to my readers, for any sort of mistakes that you may find here. The goal is to share and help. In order to do so I will need your support. Please feel free to comment me your feedback on how I can make my subsequent posts even better/helpful.
To save your time, I will try to keep my posts to the point and short.
Disclaimer: I will avoid posting any sensitive/confidential data here.
So here it goes…
Recently, I faced a ‘not-previously-faced’ issue while reading a dataset placed in another SAS Library (for now, lets call this an XYZ Library). The issue was that this xyz.dataset had an encoding different to the current SAS session encoding . My goal was to merge it with my primary dataset placed in work library. But, I was repeatedly getting the following NOTE and ERROR in my Log window:
NOTE: Data file libref.datasetname.DATA is in a format that is native to another host,
or the file encoding does not match the session encoding. Cross Environment Data
Access will be used, which might require additional CPU resources and might reduce
performance.
ERROR : Some character data was lost during transcoding in the data set
libref.datasetname. Either the data contains characters that are not
representable in the new encoding or truncation occurred during transcoding.
To understand in detail, my next step was to check the encoding of the dataset in XYZ Library and compare it with the default SAS session encoding. In order to do this, I used the below code:
/* Step 1: Show the configuration file and the encoding setting for the SAS session */
proc options option=config; run;
proc options group=languagecontrol; run;
/* Step 2:Show the encoding value for the problematic data set */
The result of the above Step 1 was:
The result of Step 2 was:
You can clearly see that the XYZ.Dataset was different from SAS session encoding. The dataset had ‘latin1’ encoding and SAS session had ‘UTF-8’ encoding.
My next step was to resolve this issue by changing the XYZ.dataset encoding in the WORK library.
Caution : You may NOT want to make any changes in your original raw dataset.
Since I did NOT want to make any change in that dataset within XYZ Library and also did not want to change the default UTF-8 encoding of the SAS session( because I feared it might affect all other useful datasets in the WORK library), I decided to first copy the xyz.dataset to WORK Lib and then change the encoding.
Below is the detailed code.
/*Careful not to change(Only If you are not supposed to) the characteristics of the original raw dataset in the source data library- */
proc copy
proc datasets library=work;
modify dataset-name/ correctencoding=utf8;
run;
Result : Clean LOG and intact data.
Hope this hack was helpful for you, because if you are reading this, then it means you have faced a similar issue.
If you liked this post, please leave a comment. If not, then also your feedback will be very valuable so that I can improve further.
Thanks for joining me!
Good company in a journey makes the way seem shorter. — Izaak Walton
I have lots of tables which I would like to sort with Proc Sort. (The names of the tables are written in a text file.) To avoid repeating the same code all over again I have tried creating a macro that would import the text file, create an array consisting of those table names and finally sort all the tables. However, I came across a few problems. In Python, I would easily be able to loop through an array. But in SAS, I am not sure how to do it.
Are you sorting the dataset in place? Because DATA=FRED and OUT=WORK.FRED will point to the same table unless you are using the USER libref so that one level names don't go into the WORK library.
Does your input list of tables really have tabs in it? It looks to me like you are treating like it is just one field per line.
The import is working fine, the datafile was changed just for the sake of privacy :D however i am not sure how to loop through this array.
Ответы 3
Я не уверен, что считаю это хорошей идеей, но если вы действительно хотите это сделать, вы можете встроить определение libname в представление с предложением using . Поместите путь в имя представления, и вам даже не придется создавать libref test .
Теперь вам не обязательно использовать один и тот же libref, но обратите внимание, что вы являются должны использовать одно и то же физическое местоположение.
Проблема заключается в «тесте» в запросе просмотра, а не в libname . Помните, представление запускается только тогда, когда вы пытаетесь получить к нему доступ.
Итак, если библиотека существует, представление может работать, но, поскольку библиотеки test не существует, оно пытается прочитать из несуществующей библиотеки.
Вот пример вашего «представления», которое работает:
@Tom предоставил обходной путь.
Создать вид
create view создает инструкции для использования при доступе к представлению для обработки. Оператор select — это проверен на синтаксис, но не проверено относительно источников данных. Таким образом, конструкция представления содержит непроверенные librefs, имена таблиц и имена столбцов, которые ей понадобятся во время обработки.
Вы можете создать представление, даже если в сеансе нет активных имен библиотек (см. Пример ниже). Создание представления сродни написанию и сохранению программы SAS, но не ее немедленной отправке.
Имя библиотеки и ссылка на библиотеку
Оператор libname создает ссылку на библиотеку или сокращенно libref. Из документации (выделено жирным шрифтом):
LIBNAME Statement
Associates or disassociates a SAS library with a libref (a shortcut name), clears one or all librefs, lists the characteristics of a SAS library, concatenates SAS libraries, or concatenates SAS catalogs.
Термин libname используется в обсуждении при идентификации экземпляра libref, но иногда имя библиотеки используется, когда имеется в виду более точный с технической точки зрения термин библиотека. Типичный опыт для пользователей SAS заключается в том, что имя библиотеки связано с одной папкой или каталогом.
Просмотр использования (исполнение)
При доступе к представлению выполняются инструкции обработки с использованием текущего состояния сеанса SAS относительно активных librefs для создания набора результатов.
Это хорошая вещь!
- В специальной среде представление может передаваться пользователям, и они могут решить, на какую библиотеку указывает библиотека.
- В производственной среде администратор SAS должен убедиться, что libref указывает на правильную и текущую библиотеку.
- Чтобы использовать представление в том же состоянии сеанса, в котором оно было создано, текущий и будущие сеансы должны иметь одинаковые librefs и необходимое содержимое библиотек.
- Если представление не работает по причинам, связанным с именами библиотек, просто создайте необходимые имена библиотек, указывающие на соответствующие библиотеки.
Пример
Ричард создатель представления
Ричард отправляет свое sasuser.lightning представление ( *.sas7bvew ) Бобу и Джейн.
Another possibility is that either a file was transported in some format other than BINARY or the attributes of the transport file changed while in transit to the target host.
An alternative cause is that your site may use a translation table other than the default. A customized translation table is set with the TRANTAB= system option. See SAS Language Reference: Dictionary for details about setting the TRANTAB= system option. Verify the value of the TRANTAB= system option:
If you discover that your site is using an alternative translation table, you must restore the option to its default value.
Then create the transport file again, transfer it to the target host, and import the file at the target host.
Another possible explanation applies to a source host that runs SAS Release 6.12 and a target host that imports the file at the target host that runs SAS Release, 6.08, 6.09E, or 6.10. Data set sort features (set through the SORTEDBY= data set option) are included in the Release 6.12 CPORT procedure but not in the Release 6.08 CIMPORT procedure.
Use either of two options to recover from this problem:
-
Disable the sorting feature by using the SORTINFO= option in the Release 6.12 CPORT procedure. Here is an example:
The SORTEDBY= data set option information is included in Release 6.12 PROC CPORT.
Catalog file open function is not supported by the XPORT engine |
DATA= or LIBRARY= parameter expected instead of CATALOG= |
Because the PROC CPORT LIBNAME= option specifies a destination member of type LIBRARY, the PROC CIMPORT must also specify either a LIBNAME= or DATA= option.
In order to select only a catalog entry type from an imported library, specify the ET= option in PROC CIMPORT. To exclude a catalog entry type, use the EET= option. Here are examples: In the first example, only catalog entries of type PROGRAM are imported. In the second example, only catalog entries of type PROGRAM are excluded. MEMTYPE=CATALOG restricts the import to catalogs only.
filename is not a SAS file |
The transport file that you are trying to import by using PROC CIMPORT may have been created by using the XPORT engine with either the COPY procedure or the DATA step. Read the beginning of the file to determine how the transport file was created. If the XPORT engine created the transport file, the beginning of the file contains this text:
If the CPORT procedure created the transport file, the beginning of that file contains this text:
Note: If you set the NOCOMPRESS option in PROC CPORT, compression is suppressed, which prevents the display of the preceding text in a transport file.
If incompatible methods were used to create and then restore the transport file, then use the correct method to restore the transport file.
Another possible explanation is that your site may use a translation table other than the default. For recovery actions for this problem, see Bad Transport File.
Entry type catalog-entry-type is not supported by CPORT |
Because you cannot retrieve the definitions from the module itself, you can try to move the SAS statements that defined the entry type (such as IML modules) to the target host and then re-create the modules.
Entry type catalog-entry-type is not compatible to earlier release |
The member name THIS_IS_LONG_NAMED_DATA exceeds the eight-character member name length, which is enforced by the Version 5 feature set in which the XPORT engine was introduced.
The VALIDVARNAME SAS system option and the assigned value of V6, which enables automatic truncation of long variable names, does not support member names. To recover, copy the member to another member whose name does not exceed 8 characters and retry the transport operation.
The Version 8 data set name MYDATABASE exceeds the maximum member name length of 8 that is supported in Version 6. Version 6 interprets the data set name MYDATABASE as containing 10 characters, which exceeds its maximum length of 8.
The VALIDVARNAME SAS system option and the assigned value of V6, which enables automatic truncation of long variable names, does not support member names. To recover, rename the member or copy it to another member whose name does not exceed 8 characters and retry the transport operation.
At the target host, you can use a host-specific utility (such as the UNIX hexadecimal dump utility xd ) to view the transport file in hexadecimal format to determine if carriage returns were inserted. See the UNIX xd (1) manual page for details. As another example, for OS/390, use the SPF 1 command for browsing, select a data set, and enter hex on in the command line.
Hexadecimal Representation of a Transport File shows an example of a transport file that contains a carriage return character (0D) and a line feed character (OA) toward the end of the first record. See the 0D and 0A hex values in the first two positions of the last line.
If you do not see carriage return or line feed characters, another form of corruption that is not immediately apparent may have occurred. To test this possibility, at the target host, create another transport file from a member of the same type and then view its hexadecimal representation. Compare the appearance of the assumed uncorrupted file that you just created with the suspected corrupted file that you are trying to restore. A visual comparison may prove that the transport file that you are trying to restore is indeed corrupt. In this case, re-create the transport file at the source host, transfer it, and restore it at the target host.
At the source host, determine whether the transport file's attributes include carriage returns. For information about listing and correcting file attributes, see the appropriate operating environment chapter.
At the source host, transfer the transport file to the target host again.
If you are still unable to restore a transport file that has the correct file attributes, you may try using the re-blocking program in Reblocking a Transport File.
Internal error from getting data |
Invalid data length |
Member or library unavailable for use in file file |
Another possible explanation applies to a Release 6.12 SAS session on a source host and a Release 6.08 SAS session on a target host. Data set sort features (specified by using the SORTEDBY= data set option) are included in the Release 6.12 CPORT procedure but not in the Release 6.08 CIMPORT procedure.
Use either of two options to recover from this problem:
-
Disable the sorting feature by using the SORTINFO= option in the Release 6.12 CPORT procedure. Here is an example:
The SORTEDBY= data set option information is included in Release 6.12 PROC CPORT.
More library members exist in the input file. For all of them to get converted, please specify LIBRARY=libref parameter in the PROC statement |
In order to expand the import operation to include the entire contents of destination library, specify the LIBRARY= option rather than the DATA= option in PROC CIMPORT.
PROC SQL will not store a V8 view into a V6 library |
To recover, transport the data set that contains the SQL table to the target host and re-create the PROC SQL view there.
Requested function is not supported |
To recover, you must remove Version 8 features from the library or the member to be moved to the library on the Version 6 host and retry the transport operation. Preceding notes in the log can hint at the offending Version 8 feature that is not supported. Here is an example:
You can infer from this message that Version 6 does not support integrity constraints.
This message can indicate that the transport file was moved to a virtual disk or shared disk with other operating environments such as DOS, Macintosh, or UNIX. For recovery actions, see the appropriate operating environment chapter.
Updating not allowed for libref.member-name because it was created for a different operating system |
UTILITY FILE OPEN function is not supported by the XPORT engine |
The Version 8 variable name Region_Of_The_Country exceeds the maximum variable name length of 8 that is supported in Version 6. To recover, in the SAS session on the local host, set the VALIDVARNAME SAS system option to V6 to enable automatic truncation of long variable names. Retry the transport operation. Here is an example of setting this variable: In this example, Region_Of_The_Country truncates to Region_O However, if the data set contains multiple variables whose first 8 characters conflict, Version 8 uses a truncation algorithm that ensures uniquely truncated variable names. For details, see Regressing SAS Data Sets from Version 8 to Version 6 Format.
There are several ways to specify a libref:
-
Use the New Library dialog box which is described in SAS System Help.
Note: You can eliminate the LIBNAME statement by directly specifying the drive name and the library name within quotes. An example follows:
Accessing the New Library Dialog Box Using the Graphical-User Interface |
To open the New Library dialog box using the toolbar, click on the New Library icon which looks like a file cabinet.
To open the New Library dialog box using a command, type libassign in the command box.
-
Select the Library folder.
Note: When a second Explorer window is open on the right side of the SAS workspace, you can by-pass the New. dialog box to open the New Library dialog box if you right-mouse click on the Libraries folder and select New. .
For more information on the New Library window and Explorer, see the SAS System Help.
The LIBNAME statement has the following basic syntax:
LIBNAME libref < engine-name >' SAS-data-library ' |
An explanation of all the arguments in this statement can be found in LIBNAME and SAS Language Reference: Dictionary .
You can also use the LIBNAME function within your SAS programs to assign librefs. For more information about the LIBNAME function, see SAS Language Reference: Dictionary . CAUTION: The words CON, NUL, LPT1 - LPT9, COM1 - COM9, and PRN are reserved words under Windows. Do not use these reserved words as librefs.
Assigning a Libref to a Single Folder
If you have Version 8 SAS data sets stored in the C:\MYSASDIR folder, you can submit the following LIBNAME statement to assign the libref TEST to that folder: This statement indicates that Version 8 SAS files stored in the folder C:\MYSASDIR are to be accessed using the libref TEST. Remember that the engine specification is optional.
Assigning a Libref to the Working Folder
Assigning a Libref to Multiple Folders
If you have SAS files located in multiple folders, you can treat these folders as a single SAS data library by specifying a single libref and concatenating the folder locations, as in the following example: This statement indicates that the two folders, C:\REVENUE and D:\COSTS, are to be treated as a single SAS data library. When you concatenate SAS data libraries, the SAS System uses a protocol (a set of rules) for accessing the libraries, depending on whether you are accessing the libraries for read, write, or update.
Furthermore, you may concatenate multiple libraries by specifying only their librefs, as in the following example: This statement indicates that two libraries that are identified by librefs INCOME and REVENUE are treated as a single SAS data library whose libref is SALES.
For more information, see Understanding How Concatenated SAS Data Libraries Are Accessed and SAS Language Reference: Dictionary .
Note: The concept of library concatenation also applies when specifying system options, such as the SASHELP and SASMSG options. For information on how to specify multiple folders in options such as these, see Syntax for Concatenating Libraries in SAS System Options.
Assigning Engines
As another example, if you plan to share SAS files between Version 8 under Windows and Release 6 under Windows, you should use the V6 engine when assigning a libref to the SAS data library. Here is an example of specifying the V6 engine in a LIBNAME statement:
The V6 engine is particularly useful in your Version 8 SAS session if you are going to be accessing the same SAS files from a Release 6 SAS session. Remember that while Version 8 can read Release 6 SAS data sets, Release 6 cannot read Version 8 SAS data sets.
For more information about using engine names in the LIBNAME statement, see Using SAS Files from Other Releases with Version 8 for Windows and Reading BMDP, OSIRIS and SPSS Files. You can also refer to the LIBNAME statement in SAS Language Reference: Dictionary .
Using the LIBNAME Statement in SAS Autoexec Files
For more information about how to create and use a SAS autoexec file, see SAS Autoexec File.
Assigning Multiple Librefs and Engines to a Folder
Data sets referenced by the libref ONE are created and accessed using the compatibility engine (V6), whereas data sets referenced by the libref TWO are created and accessed using the default engine (V8). You can also have multiple librefs (using the same engine) for the same SAS data library. For example, the following two LIBNAME statements assign the librefs MYLIB and INLIB (both using the V8 engine) to the same SAS data library: Because the engine name and SAS data library specifications are the same, the librefs MYLIB and INLIB are identical and can be used interchangeably.
-
Use the SET system option. This defines a SAS (internal) environment variable.
The availability of environment variables makes it simple to assign resources to the SAS System prior to invocation.
SET System Option
When you assign an environment variable, the SAS System does not resolve the environment reference until the environment variable name is actually used. For example, if the TEST environment variable is defined in your SAS configuration file, the environment variable TEST is not resolved until it is referenced by the SAS System. Therefore, if you make a mistake in your SET option specification, such as miss-typing a folder name, you do not receive an error message until you use the environment variable in a SAS statement.
Because Windows filenames can contain spaces or single quotes as part of their names, you should enclose the name of the physical path in double quotes when specifying the SET option. If you use the SET option in an OPTIONS statement, you must use quotation marks around the filename. For complete syntax of the SET system option, see SET.
Any environment variable name you use with a system option in your SAS configuration file must be defined as an environment variable before it is used. For example, the following SET option must appear before the SASUSER option that uses the environment variable TEST:
In the following example, environment variables are used with concatenated libraries:
Note that when you reference environment variables in your SAS configuration file or in a LIBNAME statement in your SAS programs, you must precede the environment variable name with an exclamation point (!).
It is recommended that you use the SET system option in your SAS configuration file if you invoke the SAS System through a Windows shortcut.
Windows SET Command
Operating Environment Information for Windows 95 and Windows NT Users: SAS can recognize environment variables only if they have been assigned in the same context that invokes the SAS session. That is, you must either define the environment variable in the Windows AUTOEXEC.BAT file that runs when Windows starts (thus creating a global variable), or define the variable in a Command Prompt window from which you then start SAS. Under Windows NT, you can also define the environment variable using the System Properties dialog box accessed from the System item in the Control Panel.
If you define an environment variable in a Command Prompt window, and then start SAS from the Start menu (or another shortcut), SAS will not recognize the environment variable.
The environment variables you define with the SET command can be used later within the SAS System as librefs. In the following example, the Windows SET command is used to define the environment variables PERM and BUDGET:
When you reference an external environment variable (one assigned with the Windows SET command) in your SAS programs (such as in a DATA or MERGE statement or in a SAS command), a note informing you the environment variable has been used is written to the SAS log. SAS does not recognize the environment variable as a libref until after you use it at least once during your SAS session, so the library name does not appear as a node in the SAS Explorer window until then.
Listing Libref Assignments |
If you are running the SAS System interactively, use the SAS Explorer window to view the active librefs. The SAS Explorer window lists all the librefs active for your current SAS session, along with the engine and the physical path for each libref. Any environment variables you have defined as librefs are listed, provided you have used them in your SAS session. If you have defined an environment variable as a libref but have not used it yet in a SAS program, the SAS Explorer window does not list it.
Note: You can use the LIBNAME command to invoke an 'Active Libraries' window which is a contents-only SAS Explorer that lists the active libraries, providing you with a quick view of your current libraries.
You can use the following LIBNAME statement to write the active librefs to the SAS log:
To clear a libref by using the SAS Explorer window, simply right-click on the node for the libref that you want to clear and select Delete . (For more information about using the SAS Explorer window to manage libraries, see The Little SAS Book .)
To clear a libref by using the LIBNAME statement, submit a LIBNAME statement using this syntax:
LIBNAME libref |_all_ ; |
If you specify a libref, only that libref is cleared. If you specify the keyword _all_, all the librefs you have assigned during your current SAS session are cleared. (SASUSER, SASHELP, and WORK remain assigned.)
Note: When you clear a libref defined by an environment variable, the variable remains defined, but it is no longer considered a libref--that is, it is not listed in the SAS Explorer window. You can use the variable in another LIBNAME statement to create a new libref.
The SAS System automatically clears the association between librefs and their respective data libraries at the end of your job or session. If you want to associate the libref with a different SAS data library during the current session, you do not have to end the session or clear the libref. The SAS System automatically reassigns the libref when you use it to name a new library from within either the SAS Explorer window or a LIBNAME statement.
Input and Update Access
Output Access
If a copy of the OLD.SPECIES data set exists in the second folder, it is not replaced.
Accessing Data Sets with the Same Name
In this case, the DATA statement opens TEST.SPECIES for output according to the output rules; that is, the SAS System opens a data set in the first of the concatenated libraries (C:\SAS). The SET statement opens the existing TEST.SPECIES data set in the second (D:\MYSASDIR) folder, according to the input rules. Therefore, the original TEST.SPECIES data set is not updated; rather, two TEST.SPECIES data sets exist, one in each folder.
If you display the SAS Explorer window now, you will see the SPORTS data set in the WORK folder.
You can display all the temporary data sets that are created during this session from the SAS Explorer window by double-clicking the Libraries folder icon and then double-clicking the Work folder icon. From the Active Libraries (LIBNAME) window, double-click the Work folder icon to see the temporary data sets. CAUTION: You cannot change the engine associated with the WORK data library. The WORK data library is always associated with the V8 engine. If you try to assign another engine to this data library, you receive an error message. Therefore, even if you have set the ENGINE system option to a different engine, any SAS files that are created in the WORK data library are Version 8 SAS files.
Using an Environment Variable
Note: If you specify the USE suboption in the default configuration file, you will not be able to run multiple SAS sessions on the same machine, since each SAS session requires a unique WORK folder.
Also, do not assign an environment variable named TEMP or TMP, as these variable names are usually already used by Windows.
When you set the USER libref to a folder as in the previous example, if you want to create or access a temporary data set you must specify a two-level name for the data set with WORK as the libref. You can also assign the USER libref when you invoke the SAS System by using the USER system option. For more information about the USER system option, refer to USER and SAS Language Reference: Dictionary .
Note: You can assign other engines to the USER libref if you want the data sets that are saved with one-level names to be stored in a format for use with other releases of the SAS System.
1 Answer 1
Just use an iterative %DO loop to loop over your "array" of macro variables.
But you don't need a macro for this. There are easier ways to generate code.
But then here comes another issue - the columns are called differently in each table so I'd need to tell SAS something like: SORT BY FIRST 3 columns. Is there a way to do this in SAS? Can't find anything on the Internet.
Use PROC SQL to sort? create table &&tablevar&i as select * from &&tablevar&i order by 1,2,3; But you will have trouble if any table has less than 3 columns.
Yes, it would be nice though to be able to order the tables by the number of columns they have. So if one table has 3 columns ORDER BY 1,2,3 and if another one has 5 columns then ORDER BY 1,2,3,4,5. I can't figure out how to tell PROC SQL to order it by all columns. I tried ORDER BY * - didn't work. I also tried to get count of the columns and then create and array but with the following error: ERROR: Librefs are restricted to eight characters. INFORMATION_SCHEMA has been truncated.
Я создал представление в SAS для чтения нескольких наборов данных. Я могу читать данные из этого представления, только если я укажу то же имя библиотеки, которое использовалось для создания представления.
Как SAS узнает, что вам нужен NEW.one вместо TEST.one?
Представление было прочитано нормально, выполнение представления завершилось неудачно, поскольку предварительные условия были неверными (т. е. требуемые средства доступа (имена библиотек) или конструкции (таблицы и столбцы в них) не были определены или не присутствовали)
Будучи разработчиком веб-приложений, легко впасть в заблуждение, считая, что приложение без JavaScript не имеет права на жизнь. Нам становится удобно.
Если вы ищете пакет для быстрой интеграции календаря с выбором даты в ваше приложения, то библиотека Flatpickr отлично справится с этой задачей.
Клиент для URL-адресов, cURL, позволяет взаимодействовать с множеством различных серверов по множеству различных протоколов с синтаксисом URL.
У каждого из нас бывали случаи, когда нам нужно отцентрировать блочный элемент, но мы не знаем, как это сделать. Даже если мы реализуем какой-то.
Читайте также: