BookmarkSubscribeRSS Feed
SASACC
Calcite | Level 5
Hi ,

I have a table as below :

a1 a2 a3 a4 a5 a6 a7 a8 ------------------ a20
1 2 3 4 5 6 7 8 ------------------ 100

Say , In my caluculation I got results as 8 then I should display a8(columns name) in new columns as below.

a1 a2 a3 a4 a5 a6 a7 a8 ------------------ a20 New_Columns
1 2 3 4 5 6 7 8 ------------------ 100 a8


Please help me in finding columns name from the it's value.

Many Thanks..
3 REPLIES 3
data_null__
Jade | Level 19
VNAME or
VNAMEX

e.g. name = vname(a[8]);

See documentation for details.
Cynthia_sas
SAS Super FREQ
Hi:
In a DATA step program, you can create new variables with an assignment statement:
[pre]
data newfile;
length New_Columns $2;
....either SET or INFILE/INPUT statements to read data....
...logic to figure out value of new variable ...
New_Columns = 'A8';
run;
[/pre]

What I don't understand is your statement
In my caluculation I got results as 8 then I should display a8(columns name) in new columns as below.

What calculations? The above approach will create a 2 character text variable whose value is always the string 'A8'. However, this might be the wrong approach depending on what you mean by "calculation". Also, you don't show any code or log file for what you've already tried....that might help folks visualize your logic or attempt. Is it possible to return 2 or more values from your calculations??? If so, what would happen?? Could different observations have different values calculated????

cynthia
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Also, an ARRAY may work for your needs, along with VNAME/VNAMEX, if you want concise code paragraph and the ability to detect what variable (name) has a particular value-condition. The ARRAY can declare a list of SAS variables or possibly _NUMERIC_ ...or... _CHARACTER_ to mean all SAS variables of a given type.

Yes, and it's time to crack open the DOC, with focus on the SAS Language Elements guide and the functions. Check the SAS support http://support.sas.com/ website and use its SEARCH facility in addition to the SAS forum archives and SAS system documentation.

Scott Barry
SBBWorks, Inc.

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
  • 3 replies
  • 697 views
  • 0 likes
  • 4 in conversation