BookmarkSubscribeRSS Feed
Ethan_Kael
Calcite | Level 5
I want to use pipe dir to get the filename path and import the datasets ;but if file path contains chinese-character ,will happend the stderror outout in log and i can't get the files path in unicode SAS,but it‘s ok in chinese SAS Environment,so how to modify the code?(Sure, I could use 2>&1, but we still can't get the correct file path). this is my code: %let path=C:\Users\Administrator\Desktop\中文; FILENAME DIRLIST  PIPE "DIR ""&PATH"" /B encoding='UTF8'  2>&1"  ; DATA dirlist1; INFILE dirlist  LENGTH=RECLEN ;   INPUT FILENAME $varying1024. RECLEN; path="&path"; filename1=FILENAME;   filename=CATS(path, '\', filename1);   RUN;
3 REPLIES 3
yabwon
Onyx | Level 15

Use the BasePlus package and the %dirsAndFiles() macro

e.g.

%dirsAndFiles(C:\SAS_WORK\,ODS=work.result)

It works with UTF characters (I've tested it)

 

Bart

 

P.S. Here are some instructions how to get BasePlus package and where the documentation is.

/*
Details about SAS Packages Framework:
- https://github.com/yabwon/SAS_PACKAGES

Tutorial:
- https://github.com/yabwon/HoW-SASPackages

BasePlus documentation:
- https://github.com/SASPAC/macroarray/blob/main/baseplus.md
*/

/* Step 1. */
/* Install SAS Packages Framework and BasePlus package. */
/* Run this only once. */
filename SPFinit url "https://bit.ly/SPFinit";
%include SPFinit; 
filename SPFinit clear;

/* create directory for the framework and packages */
filename packages "</your/directory/for/packages/>";
/* install the framework and the BasePlus package */ 
%installPackage(SPFinit BasePlus)


/* Step 2. */
/* From now on if you want to use a package: */
/* Run this at the beginning of your new SAS Session (or add it to autoexec). */
/* Enable framework and load package  */
filename packages "</your/directory/for/packages/>";
%include packages(SPFinit.sas); 
%loadPackage(BasePlus)

 

 

 

_______________
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



Ethan_Kael
Calcite | Level 5
Sorry, in this link i can't get the macro of %dirsAndFiles ,so i don't know how to read contains chinese-path files to use pipe dir
yabwon
Onyx | Level 15

The link it to the macro documentation. Check the "P.S." to see how to get the BasePlus package which contains the %dirsAndFiles() macro.

 

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



sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 279 views
  • 1 like
  • 2 in conversation