Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS-Read input data with variable names embedded in the data

Tags:

sas

I have input data that includes the variable name, an equal sign, and a value in the data. How can I input that data?

My input data is as follows:

name=Linda english=95 math=94 science=90
name=Susan math=88 english=91 science=90
name=Mary Louise math=90 english=84 science=81

What I've tried so far:

  data one;
    input name $ subject $;
cards;

My desired output data:

Obs    name           math
1     Linda           94
2     Susan           88
3     Mary Louise     90
like image 670
Sujit Patnaik Avatar asked Mar 03 '26 07:03

Sujit Patnaik


1 Answers

Assuming you are trying to read input from the raw data, the input method below - using the equal sign (=) after the variable name - allows you to read that format of data.

data one;                                                                                                                               
 input name=$20. english= math= science=;                                                                                               
cards;                                                                                                                                  
name=Linda english=95 math=94 science=90                                                                                                
name=Susan math=88 english=91 science=90                                                                                                
name=Mary Louise math=90 english=84 science=81                                                                                          
;                                                                                                                                       

run;
like image 79
kawsleo Avatar answered Mar 06 '26 08:03

kawsleo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!