BookmarkSubscribeRSS Feed
inquistive
Quartz | Level 8

Hi experts,

 

I have an xls worksheet as follows: 

inquistive_0-1657565271980.png

 

Upon export this is the output:

inquistive_1-1657565338660.png

My question is- why is SAS unable to import the column label (for the COMMENTS column) when I click that particular cell, only the COMMENTS is seen on the bar above .All others are displayed in full. Any idea what is the problem with this cell?

inquistive_2-1657565606694.png

 

All others are okay. 

inquistive_3-1657565638703.png

 

I believe the cell format is causing SAS not to import all info from that cell. Please advise what troubleshooting steps are required to import the column label(s)( Not sure if this is the right term though).

 

 

7 REPLIES 7
inquistive
Quartz | Level 8
proc import out= test_tmp
			datafile="C:\Users\test.xls"
            dbms =xls replace;
            getnames= yes;
run;

proc export data= test_tmp
			outfile = "C:\Users\test2.xls"
			dbms = excel replace;
			sheet = 'test1';  
run; 
Reeza
Super User

Comments looks like it has an new line/end of line character in that field which means it would truncate at the end of the line. 

Usually that gets entered into Excel when you hit ALT+ENTER in a cell.

inquistive
Quartz | Level 8
Hi Reeza,
I found it to be exactly as you suspected- there are multiple lines entered after hitting ALT+ENTER. And the end users have done it by design, not by mistake. Is there a way to tell SAS to go to consecutive lines and read/fetch them(values)?
Tom
Super User Tom
Super User

It should be doing that already.  Did you run proc contents on the dataset?  What does it show as the variable name? What does it show as the label?

 

You can use a RENAME statement to change the name of a variable.

You can use a LABEL statement to change the label attached to a variable.

 

You can fix it after the fact.

proc contents data=have noprint out=contents; run;
data fixes ;
  set have;
  where indexc(name||label,'0A0D'x);
  length newname $32 newlabel $256 ;
  newname = left(compbl(translate(name,'  ','0A0D'x)));
  newlabel = left(compbl(translate(label,'  ','0A0D'x)));
run;
proc sql noprint;
select
case when (upcase(name) ne upcase(newname)) then catx(' ',nliteral(name),nliteral(newname)) else ' ' end , catx('=',nliteral(newname),quote(trim(label),"'")) into :rename separated by ' ' , :label separated by ' ' from fixed ; quit; data want ; set have; rename &rename ; label &label; run;
Tom
Super User Tom
Super User

Not sure why you are not seeing the whole name.

What tool did you use to view the dataset so that you could take that photograph you pasted?

What does PROC CONTENTS show?

Remember that the NAME of a variable can only be 32 bytes long.  And unless you have (accidentally?) set the VALIDVARNAME option to ANY it cannot include spaces and other special characters.  But the original header cell value should be stored in the LABEL of the variable.

 

Example:

6    proc import datafile='c:\downloads\example.xls' dbms=xls out=test replace;
7    run;

NOTE:    Variable Name Change.  Space in name -> Space_in_name
NOTE:    Variable Name Change.  Linebreak
in name -> Linebreak_in_name
NOTE:    Variable Name Change.  Name that is more than thirty-tw -> Name_that_is_more_than_thirty_tw
NOTE: The import data set has 1 observations and 4 variables.
NOTE: WORK.TEST data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


8
9    proc contents data=test varnum out=contents;
10   run;

NOTE: The data set WORK.CONTENTS has 4 observations and 41 variables.
NOTE: PROCEDURE CONTENTS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


11
12   proc print data=contents;
13     var varnum name type length label;
14   run;

NOTE: There were 4 observations read from the data set WORK.CONTENTS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
                                             Variables in Creation Order

#    Variable                            Type    Len    Format     Label

1    ID                                  Num       8    BEST12.    ID
2    Space_in_name                       Num       8    BEST12.    Space in name
3    Linebreak_in_name                   Num       8    BEST20.    Linebreak
in name
4    Name_that_is_more_than_thirty_tw    Num       8    BEST12.    Name that is more than thirty-two characters long


Obs    VARNUM    NAME                                TYPE    LENGTH    LABEL

 1        1      ID                                    1        8      ID
 2        3      Linebreak_in_name                     1        8      Linebreak
in name
 3        4      Name_that_is_more_than_thirty_tw      1        8      Name that is more than thirty-two characters long
 4        2      Space_in_name                         1        8      Space in name

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1707 views
  • 4 likes
  • 4 in conversation