BookmarkSubscribeRSS Feed
Seb_A_Sanders
Calcite | Level 5

The database setup at my organisation is SQL Server tables copied onto our SAS server. The SQL tables were setup to run pre-programmed SQL queries, but now SAS is the tool used. This however creates an issue with some tables having variables that are too long for SAS, but work in SQL. The label for the source variable is correct and not shortened.

 

The source table (in SQL Server) names:

Consolidated_Arrears_Vs_Portfolio_Balance_Ltd

Consolidated_Arrears_Vs_Portfolio_Balance_Pure

 

In SAS:

Consolidated_Arrears_Vs_Portfoli

Consolidated_Arrears_Vs_Portfoli

 

SAS Labels:

Consolidated_Arrears_Vs_Portfolio_Balance_Ltd

Consolidated_Arrears_Vs_Portfolio_Balance_Pure

 

So, how do I tell the difference between these two when I'm writing code / query builder?

 

Thanks in advance.

 

(I have no control over the SQL Server code so I can't change the underlying tables or how these are copied to the SAS server)

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use named literals:

select 'consolidated_arrears_vs_portfolio_balance_ltd'n

Note the quotes and the n.  Or you can set:

options validvarname=any;

Which basically means you can write any old rubbish you like, and the next guy will love you for it.

Seb_A_Sanders
Calcite | Level 5

Hi,

 

I've tried this, but I'm continuing to receive this message:

 

PROC SQL;

create table testing
as select
'consolidated_arrears_vs_portfolio_balance_chl'n
____________________________________________
65
ERROR 65-58: Name ''consolidated_arrears_vs_portfolio_balance_chl'N' is too long for a SAS name in this context.

FROM REP.va_me_local;
run;

I have also included the

options validvarname=any; 

prior to this.

 

Thanks,

 

 

 

 

mkeintz
PROC Star

The validvarname=any option permits special characters and embedded blanks (and leading blanks) in name literals. But unfortunately it does not escape the 32-byte limit.  You'll need another approach.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

I don't know if this will work, but it's worth testing.  Have you tried shortening the name on the fly, something like:

 

select Consolidated_Arrears_Vs_Portfolio_Balance_Ltd as Cons_Arrears_vs_Port_Bal_Ltd

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Seb_A_Sanders 

 

I think your only way out of the problem is to use SQL passthru. This way you can handle +32 long names of both tables and columns. Se the following code, which is a subset of working production code cut down to 3 variables:

 

options Validvarname = V7;
proc sql;

    connect using xkmdne as sconn;

    create table &_OUTPUT (label="archive_NEXUS2_medicine_medication_additional_information") as
        select 
			medication_id 
				length=8 ,
             administratively_deleted_datetim
                length=8
                format=nldatm20.
                label="administratively_deleted_datetime" ,
             last_past_fmk_dosage_period_end_
                length=8
                format=ddmmyyd10.
                label="last_past_fmk_dosage_period_end_date" 

        from connection to sconn (
            select
                medication_id,
                administratively_deleted_datetime     
					as administratively_deleted_datetim,
                last_past_fmk_dosage_period_end_date  
					as last_past_fmk_dosage_period_end_
            from archive_NEXUS2_medicine_medication_additional_information
        );

    disconnect from sconn;
quit;

Explanation:

 

Make a connection to the relevant SQL database using a previously assigned libname to the database.

 

Create a new SAS table with name abbreviated to 32 chars. Use original SQL table name as dataset label. select from connection to database, use original SQL column names as variable labels. 

 

Connection to database gives the result of the second select, where long column names are abbreviated to sonething useful. This select is sent to execution in the database, so all long names are kept on the SQL Server side, and SAS sees only your abbreviations.

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
  • 675 views
  • 3 likes
  • 5 in conversation