Hi,
Is there a way to create variable names using string from an observation. This is where I got with the code:
DATA SASDATA.BAD1_REPAIRED;
SET SASDATA.BAD1;
COUNT + (-(LAG(FLAG) EQ 'LAST')*COUNT) + 1;
DO FIELD&S. = TOTAL_TEXT (S = COUNT); END;
RUN;
I am trying to do this
INPUT:
total_text count
abcdef 1
adfgh 2
LAST 3
OUTPUT:
total_text count field1 field2 field3
abcdef 1 abcdef
adfgh 2 adfgh
LAST 3 LAST
Please help. Thanks again for your help.
-Akber.
Need help please!!!!
Akber, a proc transpose should do it.
data x;
input total_text $ count;
datalines;
abcdef 1
adfgh 2
LAST 3
;
run;
proc transpose data = x out=tx(drop=_name_) prefix=field;
by total_text notsorted;
id count;
var total_text;
run;
HTH,
Rich
Here is array method.
data x; input total_text $ count; datalines; abcdef 1 adfgh 2 LAST 3 ; run; proc sql; select max(count) into : n from x; quit; data want; set x; array field{&n} $ ; field{count}=total_text; run;
Ksharp
From your example it does not look like you want to create variable names, instead you want to put text into a matrix of variables.
The only thing you need to calculate before writing the code is the maximum number of counts.
Perhaps if you explained more about WHY you would want to do this you might get a better answer.
data have ;
input total_text :$32. count @@;
cards;
abcdef 1 adfgh 2 LAST 3
run;
proc sql noprint;
select max(count) into :max from HAVE ;
quit;
data want ;
set have;
array field (&max) $32 ;
field(count)=total_text;
run;
proc print; run;
total_
Obs text count field1 field2 field3
1 abcdef 1 abcdef
2 adfgh 2 adfgh
3 LAST 3 LAST
Oh..
its looks very simple..
Great skill tom..
Hi,
The reason why I want to do this is because these are actually parts of line but some data system is outputting them into different lines. So I want to retain until you have LAST in the data. So, what it will do is create one line in the final dataset. But this works and is quite simple.
Thanks again.
-Akber.
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.