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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 739 views
  • 2 likes
  • 3 in conversation