SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xyxu
Quartz | Level 8

I have been stuck by this for several hours. I first tried

 

proc import datafile = "&path\example"
out = x
dbms = xlsx
replace;
getnames = yes;
run;

it can work, but the date variable is recognized as character. I also tried to save the excel file as csv, but Chinese characters will be missing. 

 

A small example data is attached.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What encoding are you using in your SAS session?  Check the ENCODING option.  You should be using  UTF-8.

You need to start SAS with the right encoding setting if you want to be able to read multi-byte character sets.

 

But if your only issue is that your date variable is character then just convert it.

data want ;
  set have ;
  numdate = input(chardate,yymmdd10.);
  format numdate yymmdd10. ;
run;

Perhaps the things that look like hyphens between the parts of the date values are not really hyphens?  If so then you could remove them using COMPRESS() function.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

What encoding are you using in your SAS session?  Check the ENCODING option.  You should be using  UTF-8.

You need to start SAS with the right encoding setting if you want to be able to read multi-byte character sets.

 

But if your only issue is that your date variable is character then just convert it.

data want ;
  set have ;
  numdate = input(chardate,yymmdd10.);
  format numdate yymmdd10. ;
run;

Perhaps the things that look like hyphens between the parts of the date values are not really hyphens?  If so then you could remove them using COMPRESS() function.

xyxu
Quartz | Level 8

Thanks for the reply! Yes, I was using SAS 9.4 (Chinese) version. I can use proc import and then convert chardate to date. However, when I sort nodupkey with Chinese-valued variables, the result messes up. 

 

Would this be caused by the length of these variables? One of them is $152. 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 2103 views
  • 1 like
  • 3 in conversation