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

Hello Experts,

 

I wonderring if there is some function that permits us to read the name of column (from first to last).

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

 

MarieT_0-1629191309002.png

 

I would like to have the data like that (for example for J009)

 

MarieT_0-1629200756396.png

 

 

 

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.

View solution in original post

6 REPLIES 6
JosvanderVelden
SAS Super FREQ
Can you explain with a small example with a 'have' dataset example and 'want' dataset example?
Is it something like this?:
Have:
ID var1 var2
J01 1 1
Want:
ID var1 var2
J01 var1 var2
?????
SASdevAnneMarie
Barite | Level 11
Thank you for your message,
I added the image of "want" dataset.
ballardw
Super User

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.

 

PaigeMiller
Diamond | Level 26

I feel compelled to ask the obvious questions:

 

  • What is the point of having a data set with ALL values equal to 1?
  • What is the point of doing work to create the final data set? What is the benefit? What would be the next step after you do the creation of this final data set?
--
Paige Miller
ballardw
Super User

@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.

 

MarieT_0-1629191309002.png

 

I would like to have the data like that (for example for J009)

 

MarieT_0-1629200756396.png

 

 

 

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.

Ksharp
Super User
data _null_;
 set sashelp.class;
 length _name_ $ 40;
 do until(_name_=' ');
  call vnext(_name_);
  put _name_=;
 end;
 stop;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 987 views
  • 4 likes
  • 5 in conversation