BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Thomas_mp
Obsidian | Level 7

Hello. I would like to add some values to one of the variables (Va).  I would like to add some code, but the first problem I encounter is how to read the data, given that all the variables (in row B in the attached file) have the same name for different individuals (in row A). Attached is a simplified version of my dataset, what I have in the first 11 rows, and what I would like to have. Could you please help me with this?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

"Va for individual 1 has 1 value of 27, and I would like to have 3 values of 27"

So where is 24 coming from , I did not see it in your data ?

Here could give you a start.

 

libname x 'C:\Users\xiakeshan\Documents\Downloads';

proc transpose data=x.delete_data_sas(obs=2) out=temp;
var _all_;
run;
proc sql noprint;
select cat('length temp_',_name_,' $ 80;retain temp_',_name_,'; if _n_>2 then do;if not missing(',_name_,') then temp_',_name_,'=',_name_,';else ',_name_,'=temp_',_name_,';end;') 
into :impute separated by ' '
 from temp
  where lowcase(col2)='va';
quit;

data want;
 set x.delete_data_sas;
 &impute.
 drop temp_:;
run;

Ksharp_0-1747965011859.png

 

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Most of us will not download Excel (or other Microsoft Office) files because they can be security threats. Better to present the data using working SAS data step code (examples and instructions) or the less desirable action is to show us a screen capture of the Excel file using the "Insert Photos" icon (do not attach files)

 

In general, you can read Excel with PROC IMPORT, or LIBNAME with the Excel engine.

--
Paige Miller
Thomas_mp
Obsidian | Level 7

Thank you Paige.

Attached is the data again.  Please note that the first row is the individual IDs, and the second row is the Vbles, tehy ahve the same name for all the individuals.  This is data, and what I would like to have

Thomas_mp_0-1747938164018.png

 

PaigeMiller
Diamond | Level 26

The title of your post indicates you want to add some values. Please explain this in more detail.

--
Paige Miller
Thomas_mp
Obsidian | Level 7

Thank you Paige.

Va for individual 0 has 1 value of 23, but I would like to have 5 values of 23 for Va (because there are 5 values for Vb.  Similarly, Va for individual 1 has 1 value of 27, and I would like to have 3 values of 27 (because there are 3 values for Vb); similarly Va for individual 2 has 1 value equal to 33, but I would like to have  8 values of 33 because there are 8 values of Vb.  The idea is to fill the data in the different columns of Va .  I hope this helps !!!

PaigeMiller
Diamond | Level 26

I think I get it, but this really is a job that is perfectly and easily done in Excel. It probably could be done in SAS, but it would take a lot more effort.

--
Paige Miller
Ksharp
Super User

"Va for individual 1 has 1 value of 27, and I would like to have 3 values of 27"

So where is 24 coming from , I did not see it in your data ?

Here could give you a start.

 

libname x 'C:\Users\xiakeshan\Documents\Downloads';

proc transpose data=x.delete_data_sas(obs=2) out=temp;
var _all_;
run;
proc sql noprint;
select cat('length temp_',_name_,' $ 80;retain temp_',_name_,'; if _n_>2 then do;if not missing(',_name_,') then temp_',_name_,'=',_name_,';else ',_name_,'=temp_',_name_,';end;') 
into :impute separated by ' '
 from temp
  where lowcase(col2)='va';
quit;

data want;
 set x.delete_data_sas;
 &impute.
 drop temp_:;
run;

Ksharp_0-1747965011859.png

 

Thomas_mp
Obsidian | Level 7

Thank you very much for your help !!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1055 views
  • 1 like
  • 3 in conversation