BookmarkSubscribeRSS Feed
sumi_saslearner
Fluorite | Level 6

Hi,

 

I am loading a table in sql from a sasdataset. There are a few columns in the sql table with the datatype "text". 

Those which are in sasdataset are "varchar" type. So when i try to load I am getting datatype mismatch. How to match the datatype of "varchar" in sas dataset with "text" column in sql table?

9 REPLIES 9
yabwon
Onyx | Level 15

1) what code do you use?

2) what errors/log messages do you get?

3) what database?

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sumi_saslearner
Fluorite | Level 6
using sql server
sas code:
DATA SAMPLE_DATA;
SET SAMPLE_DATA1;
FORMAT COL_VALUE_20 $10000.
COL_VALUE_21 $10000.
COL_VALUE_22 $10000.
COL_VALUE_23 $10000.;
 
COL_VALUE_50 = ENTITY_KEY;
COL_VALUE_49 = NPN;
COL_VALUE_48 = TIN;
COL_VALUE_20 = tranwrd(OWNER,'0D'x,'$|**|$');
COL_VALUE_21 = tranwrd(IMPACTFUL_AGENT,'0D'x,'$|**|$');
COL_VALUE_22 = tranwrd(BOB_BY_ST,'0D'x,'$|**|$');
COL_VALUE_23 = tranwrd(TOP_DOWNLINE,'0D'x,'$|**|$') ;
RUN;
 
 
PROC SQL;
INSERT INTO D.SAMPLE
(COL_VALUE_50,COL_VALUE_49,COL_VALUE_48,COL_VALUE_20, COL_VALUE_21,COL_VALUE_22,COL_VALUE_23)
Select COL_VALUE_50,COL_VALUE_49,COL_VALUE_48,COL_VALUE_20, COL_VALUE_21,COL_VALUE_22,COL_VALUE_23 
From SAMPLE_DATA;
QUIT;
 
 
ERROR LOG: 
 
WARNING: Character expression will be truncated when assigned to character 
         column COL_VALUE_20.
WARNING: Character expression will be truncated when assigned to character 
         column COL_VALUE_21.
ERROR: Value 20 on the SELECT clause does not match the data type of the 
       corresponding column listed after the INSERT table name.
ERROR: Value 21 on the SELECT clause does not match the data type of the 
       corresponding column listed after the INSERT table name.
WARNING: Character expression will be truncated when assigned to character 
         column COL_VALUE_22.
WARNING: Character expression will be truncated when assigned to character 
         column COL_VALUE_23.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of 
      statements.
37         QUIT;
 
SQL TABLE STRUCTURE:
 
CREATE TABLE [dbo].SAMPLE(
[STATUS_IND] [smallint] NULL,
[COL_VALUE_20] [text] NULL,
[COL_VALUE_21] [text] NULL,
[COL_VALUE_22] [text] NULL,
[COL_VALUE_23] [text] NULL,
[COL_VALUE_24] [text] NULL,
[COL_VALUE_25] [text] NULL,
[COL_VALUE_26] [text] NULL,
[COL_VALUE_27] [text] NULL,
[COL_VALUE_28] [text] NULL,
[COL_VALUE_29] [text] NULL,
[COL_VALUE_30] [text] NULL,
[COL_VALUE_46] [varchar](255) NULL,
[COL_VALUE_47] [varchar](255) NULL,
[COL_VALUE_48] [varchar](255) NULL,
[COL_VALUE_49] [varchar](255) NULL,
[COL_VALUE_50] [varchar](255) NULL) 
yabwon
Onyx | Level 15

what is the result of:

proc contents data=SAMPLE_DATA;
run;

(variables attributes)?

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sumi_saslearner
Fluorite | Level 6

This is the output of proc contents

SAS Output     
      
      
      
Alphabetic List of Variables and Attributes  
VariableTypeLenFormatInformatLabel
COL_VALUE_20Char10000$10,000.00  
COL_VALUE_21Char10000$10,000.00  
COL_VALUE_22Char10000$10,000.00  
COL_VALUE_23Char10000$10,000.00  
COL_VALUE_24Char200   
COL_VALUE_25Char200   
COL_VALUE_48Char10   
COL_VALUE_49Char10   
COL_VALUE_50Char10   
yabwon
Onyx | Level 15

ok, and what is the default length for COL_VALUE_20 variable in the SQL Server (the TEXT type variable in the system setup)?

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Sajid01
Meteorite | Level 14

Hello @sumi_saslearner 
Have a look at the following reference
https://www.mssqltips.com/sqlservertip/2771/using-sas-access-and-proc-sql-to-save-sas-data-in-sql-se...

Please note SQL server does support varchar formats whereas in SAS, CAS supports varchar but not SAS 9.4 .

sumi_saslearner
Fluorite | Level 6

Holds a string with a maximum length of 65,535 bytes

Tom
Super User Tom
Super User

I would first try using the DBTYPE= dataset option to tell SAS what database type should be used for those variables.

 

If that does not work then you might have to upload to an another table that has normal variables and then use pass thru SQL to copy into the target table with the TEXT variables.

 

How much data are you moving?  if only a little the perhaps you can just generate the MS/SQL/SERVER code to insert the data and run that via SQL Pass thru.

sumi_saslearner
Fluorite | Level 6
Thanks will try. For now, only small number of rows but it might increase as we go..

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
  • 9 replies
  • 370 views
  • 3 likes
  • 4 in conversation