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

Hi experts,

 

I have one variable named as Country and it has values below


India
Unites States of America
United Arab Emirates

 

Need to create diffrent variables using these values example var1-india var2 United var3-States Var4-of var5-America etc....

 

and this needs to be dynamic ,( not with hardcoded)  Please advice

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Whatever you are intending to do with this data, there are probably better ways.  But here is one way to get what you ask:

 

data each_word;

set have;

if country  >  ' ' then do _n_= 1 to countw(country);

   word = scan(country, _n_);

   total_words + 1;

   output;

end;

run;

proc transpose data=each_word out=want (drop=_name_) prefix=var;

   var word;

   id total_words;

run;

View solution in original post

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

Second quick question, what is the question?  Post example test data in the form of a datastep using a code window (its the {i}) and what the output should look like.   Then explain any logic between.  If it is just splitting a string up into component parts then:

data want;
  set have;
  array var{5} $200;
  do i=1 to countw(your_string," ");
    var{i}=scan(your_string,i," ");
  end;
run;
ambadi007
Quartz | Level 8

Hi , This was  my need , thanks

Astounding
PROC Star

Whatever you are intending to do with this data, there are probably better ways.  But here is one way to get what you ask:

 

data each_word;

set have;

if country  >  ' ' then do _n_= 1 to countw(country);

   word = scan(country, _n_);

   total_words + 1;

   output;

end;

run;

proc transpose data=each_word out=want (drop=_name_) prefix=var;

   var word;

   id total_words;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 757 views
  • 1 like
  • 4 in conversation