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

 

Hello, How to get the file  WANT starting from HAVE ?

 

data HAVE;

infile datalines truncover;

input var1 $200.;

datalines;

(S) Benefit

plans

(S) car

allowance

(S) Technology,

Economic Development Initiative

Motor allowance

(S) Small Business and Tourism

Agriculture

(S) Small Business

Financing Act

;

run;

 

DATA WANT;

format var1 $200.;

var1="(S) Benefit plans"; output;

var1="(S) car allowance"; output;

var1="(S) Technology, Economic Development Initiative Motor allowance"; output;

var1="(S) Small Business and Tourism Agriculture"; output;

var1="(S) Small Business Financing Act"; output;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Here is one way:

data HAVE;
  infile datalines truncover;
  input var1 $200.;
  datalines;
(S) Benefit
plans
(S) car
allowance
(S) Technology,
Economic Development Initiative
Motor allowance
(S) Small Business and Tourism
Agriculture
(S) Small Business
Financing Act
;
run;

data want (drop=_:);
  length var1 $200;
  retain var1;
  merge have (rename=(var1=_var1_in)) have (firstobs=2 rename=(var1=_var1_next));
  if first(_var1_in) eq '(' then var1=_var1_in;
  else var1=catx(' ',var1,_var1_in);
  if missing(_var1_next) or first(_var1_next) eq '(' then output;
run;

Art, CEO, AnalystFinder.com

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

Here is one way:

data HAVE;
  infile datalines truncover;
  input var1 $200.;
  datalines;
(S) Benefit
plans
(S) car
allowance
(S) Technology,
Economic Development Initiative
Motor allowance
(S) Small Business and Tourism
Agriculture
(S) Small Business
Financing Act
;
run;

data want (drop=_:);
  length var1 $200;
  retain var1;
  merge have (rename=(var1=_var1_in)) have (firstobs=2 rename=(var1=_var1_next));
  if first(_var1_in) eq '(' then var1=_var1_in;
  else var1=catx(' ',var1,_var1_in);
  if missing(_var1_next) or first(_var1_next) eq '(' then output;
run;

Art, CEO, AnalystFinder.com

Astounding
PROC Star

Another way to get from the HAVE data to the WANT data:

 

data want;

length var1_combined $ 200;

do i=1 to 2;

   set have;

   if i=1 then var1_combined = var1;

   else var1_combined = catx(' ', var1_combined, var1);

end;

keep var1_combined;

rename var1_combined = var1;   /* optional */

run;

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
  • 2 replies
  • 1375 views
  • 1 like
  • 3 in conversation