BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Chris_Revill
Fluorite | Level 6

Hi there

 

So I regularly use a piece of code that's a couple of thousand lines long. Every time I use it, I generally have to make a few small amendments to fit the current situation. I may have to change 10-15 small snippets of the code and I find it's easy to forget one or two. This can either result in wasted time by having to rerun the code or could actually allow errors in my output, so I'm trying to reduce the number of changes I have to make. One of the changes is the input part of the data step. This wasn't my code originally so feel free to not comment on the general structure too much! A whole load of variables are listed in the format section of the data step and then there is an input command similar to the below.

 

input A--F;

 

I often add new columns and I have to add this to about 5 data steps, which means I also have to change the input statement 5 times.

 

Is there a way I can say something like:

 

input A--EOF;


?

 

I know EOF doesn't work and I've tried googling for an answer with no success.

 

I could change the way the code is written in a more substantial way to reduce the burden but other people still use the code and have been using it for a long time, so I'd rather not mess with it too much if I don't need to.

 

Thanks in advance for any help.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, first off, why is the data structure changing.  It sounds like a broken import process.  Get import specification document built, agred, and programmed upon that.  Any change then incurs a full process change - which also helps as they will be less likely to change the data. 

 

As for you request, why not just put a macro variable in place:

%let cols=A--F;

 

data a;

  input &COLS.;

run;

data b;

  input &COLS.;

run;

...etc.

 

You would only have to change it once then.  Although if you fix the cause of the problem...

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, first off, why is the data structure changing.  It sounds like a broken import process.  Get import specification document built, agred, and programmed upon that.  Any change then incurs a full process change - which also helps as they will be less likely to change the data. 

 

As for you request, why not just put a macro variable in place:

%let cols=A--F;

 

data a;

  input &COLS.;

run;

data b;

  input &COLS.;

run;

...etc.

 

You would only have to change it once then.  Although if you fix the cause of the problem...

Chris_Revill
Fluorite | Level 6

Thanks for your response. A little context may help you understand my situation. I'm a marketing analyst using SAS to process text files that have been output from a campaign management system. A lot of the segmenting is done in SAS and so when new requirements arise for the purposes of segmentation (almost a weekly occurrence at the moment) it often requires a new field to be created in the initial system and accommodated for in the SAS code.

 

The reason A--F is currently used is because a field is defined in the initial format statement that isn't an input and is populated later in the data step. I could probably make my life easier by simply moving this field to a later format statement and then I think I could replace "input A--F;" with "input;"? That is the solution is eluded to in my initial question. On reflection it's hardly a massive change for other users to accept and would be the most sensible. Another less pretty solution would be to make any new fields the second to last field in the output, rather than the last. Nowhere near as fool-proof though.

 

I'm relatively new to SAS so still learning and I appreciate your response.

 

Edited for SPAG.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sounds to me like the setup at the segmentation level wasn't done properly:

"A lot of the segmenting is done in SAS and so when new requirements arise for the purposes of segmentation (almost a weekly occurrence at the moment) it often requires a new field to be created in the initial system and accommodated for in the SAS code."

 

If a dataset is going to expand, normlise it (i.e. long rather than wide), so more rows appear rather than columns, or have an automated sql describe so processes further down the line don't need to consistently change.  Your left jumping at each change currently by the sounds of it.

Chris_Revill
Fluorite | Level 6
You make a fair point. I'm working as a contractor though so I'm not about to start fundamentally changing all of their processes. Not to mention they're in the middle of a migration to a new system which should hopefully (from their perspective) eliminate the need for SAS altogether. In the meanwhile I am starting to get to a point where code changes won't be necessary on a weekly basis. The same segmentations are done regularly. In the past they always amended the code to cater only for the segmentation required that week. As and when each one comes up now, I'm adding it to the existing process. So eventually, weeks rather than months, no further amendments will be necessary. Thanks for the advice though. I may make use of it in future.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 951 views
  • 2 likes
  • 2 in conversation