BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bharath86
Obsidian | Level 7

Hi, 

 

This macro outputs XPT files with file names in 'uppercase'. Can we change this and give the output filenames in 'lowercase'?

 

You can use any sas dataset from your directory. Please change the path (input path and output path) or you can use sashelp library too.

 

%macro xpt;
libname raw_sets " input Path ";
proc contents data=raw_sets._all_ out=datasets  noprint;
run;
proc sql noprint;
select distinct(MEMNAME),count(distinct(MEMNAME)) into:alldata1-,:datan
from datasets;
quit;
/*%put &alldata1,&datan;*/
%do i=1 %to &datan;
libname raw_xpt xport "output path\&&alldata&i...xpt";
proc copy in=raw_sets out=Raw_xpt memtype=data; select &&alldata&i.; run; %end; %mend xpt; %xpt;

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
libname raw_xpt xport "output path\&&alldata&i...xpt";
----->
libname raw_xpt xport "output path\ %lowcase( &&alldata&i...xpt ) ";

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Why not just use the LOWCASE() function?

Fix the SQL step.

proc sql noprint;
  select distinct lowcase(MEMNAME)
    into :alldata1-
  from datasets
  ;
%let datan=&sqlobs;
quit;

 

You could also get rid of the macro (or at least the macro logic and macro variables).

libname raw_sets " input Path ";
proc contents data=raw_sets._all_ out=datasets  noprint;
run;
data _null_;
  set datasets;
  by memname;
  if first.memname;
  call execute(catx(' '
   , 'libname raw_xpt xport'
   , quote(cats('output path/', lowcase(memname), '.xpt'),"'")
   , ';'
   , 'proc copy in=raw_sets out=raw_xpt mt=data;'
   , 'select', memname, ';'
   , 'run;'
  ));
run;
Ksharp
Super User
libname raw_xpt xport "output path\&&alldata&i...xpt";
----->
libname raw_xpt xport "output path\ %lowcase( &&alldata&i...xpt ) ";
bharath86
Obsidian | Level 7
Simple and Elegant.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 975 views
  • 2 likes
  • 3 in conversation