Hello Experts,
I wonderring if there is some function that permits us to read the name of column (from first to last).
@SASdevAnneMarie wrote:
Hello Experts,
I wonderring if there is some function that permits us to read the name of column (from first to last).
I would like to replace the "1" in each column by the name of the column, the ID in my data is CD_produit.
I would like to have the data like that (for example for J009)
Thank you for your help !
Proc transpose will create a _name_ variable for each variable on the VAR statement of the procedure call.
I am not going to retype stuff from pictures especially since we can't even tell exactly what one or more of your variable names are because the pictures truncate the names.
Proc transpose data=yourdataset out=transposed;
by <your grouping variables>;
var <list all those numeric variables>;
run;
There will be one or more COL variables holding the numeric values. If you don't want those drop them afterwards.
The data set will need to be sorted by the grouping variables before the Proc transpose.
Note to any interested readers: OP changed the "want" appearance from having all values in a single column the name of the variable to something mixing them after I posted this partial possible solution to the original "want". Without any rules.
If a variable is numeric you cannot place text like a variable name as values in that variable. To hold text the variable must be character. If your variable is character it must have a length long enough to hold the name.
You can create a format that will show different text for a value though.
Example:
Data have; input somevariable; datalines; 1 ;
Proc format;
value somevariable
1='somevariable'
;
proc print data=have;
format somevariable somevariable. ;
run;
You would need one format for each variable.
I feel compelled to ask the obvious questions:
@SASdevAnneMarie wrote:
Hello Experts,
I wonderring if there is some function that permits us to read the name of column (from first to last).
I would like to replace the "1" in each column by the name of the column, the ID in my data is CD_produit.
I would like to have the data like that (for example for J009)
Thank you for your help !
Proc transpose will create a _name_ variable for each variable on the VAR statement of the procedure call.
I am not going to retype stuff from pictures especially since we can't even tell exactly what one or more of your variable names are because the pictures truncate the names.
Proc transpose data=yourdataset out=transposed;
by <your grouping variables>;
var <list all those numeric variables>;
run;
There will be one or more COL variables holding the numeric values. If you don't want those drop them afterwards.
The data set will need to be sorted by the grouping variables before the Proc transpose.
data _null_;
set sashelp.class;
length _name_ $ 40;
do until(_name_=' ');
call vnext(_name_);
put _name_=;
end;
stop;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.