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
Amethyst | Level 16

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
Amethyst | Level 16

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1543 views
  • 1 like
  • 2 in conversation