BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi

No idea if this is the right place to put this - please let me know where if not.

New to SAS (new gig, new tools). I am trying to adjust a macro that takes input from a delimited, variable length file and spits it into a SAS output file. I want to select a subset of columns and change the order. How might I do this please? Below indicative of what I am trying to do. I would like the output columns to be THATCOLUMN and then THISCOLUMN. Any help very gratefully received.

%macro test_macro (indset =, outdset =);
data &outdset (keep = THATCOLUMN THISCOLUMN);
infile &indset delimiter = '|' dsd truncover lrecl = 1500;
input THISCOLUMN : 9.
THATCOLUMN : 9.
ANOTHERCOLUMN : 9.;
run;
%mend test_macro;

Thanks
2 REPLIES 2
Olivier
Pyrite | Level 9
Just add a LABEL statement for your variable between the DATA and the INFILE statement ; in that LABEL, give the names of the columns in the order that you want them at the end...

%macro test_macro (indset =, outdset =);
data &outdset (keep = THATCOLUMN THISCOLUMN);
LENGTH THATCOLUMN = "That column" THISCOLUMN = "This column" ;
infile &indset delimiter = '|' dsd truncover lrecl = 1500;
input THISCOLUMN : 9.
THATCOLUMN : 9.
ANOTHERCOLUMN : 9.;
run;
%mend test_macro;
deleted_user
Not applicable
Brilliant thanks Oliver. Obviously, you gave the right answer but got distracted when you wrote out the code (LENGTH rather than LABEL).

I appreciate that a lot 🙂

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 698 views
  • 0 likes
  • 2 in conversation