BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

Hi All,

I have data issue while making reshape of the below data, kindly someone help me out for this scenario

 

   data _nu;

   infile datalines;

   input num1

   datalines;

   1 2 3 4 5 ;

  run;

my expecting results should be 

 

num1

 1

 2

 3

 4

 5

I want to reshape horizontal to vertical 

 

Thanks & regards

Rohit 

 

 

 

17 REPLIES 17
PeterClemmensen
Tourmaline | Level 20
data wide;
input num1-num5;
datalines;
1 2 3 4 5
;

proc transpose data=wide out=long(rename=COL1=num drop=_NAME_);
run;
Kurt_Bremser
Super User

Please supply a WORKING step with datalines.

Is num1 thought to be a string with all the digits, or do you rather have 5 numerical values in one observation?

Or do you want to read a text file that has all the numbers on one line?

That would be very easy with a "double hold":

data _nu;
infile datalines;
input num1 @@;
datalines;
1 2 3 4 5
;
run;
novinosrin
Tourmaline | Level 20

Adding some fun

 

data _nu;
infile datalines;
array num(5);
input num(*);
do _n_= 1 to 5;
 numbers=num(_n_);
 output;
end;
keep numbers;
datalines;
1 2 3 4 5 
;
run;
rohitkrishna
Calcite | Level 5
HI KurtBremser, novinosrin
Thanks for the quick replay
I just asked for example how it works for reshaping horizontal to vertical for my existing SAS code so kindly share the solution for real sas code
{
data _null_;
infile ssassdt missover;
INPUT @17 Inamlin1 $Char28.
@45 Inamlin2 $Char28.
@79 Idtype $Char7. @@;

PUT @17 Inamlin1 $Char28.
@45 Inamlin2 $Char28.
@79 Idtype $Char7. ;
return;}
but it going in loop while removing the missover
if missover is there it throughs error code 8.
kindly give some suggestion for this problem
Thanks & regards;
rohit
novinosrin
Tourmaline | Level 20

Hi @rohitkrishna   Can you post a sample of the data you have and your expected output that you want plz?  Makes it easier to code it for you

rohitkrishna
Calcite | Level 5
Hi novinosrin
Thanks for the response
please find below mention data
{
R M********N T**B
D N******E T**B
L H**********N T**B
R S***********N T**B
K *******L T**B
Thanks & regards
rohit
novinosrin
Tourmaline | Level 20

Okay and what is the output you want from that?

rohitkrishna
Calcite | Level 5
Ya novinosrin,
i want the rec into vertical
like
R M********N
T**B
like above one after another
Thanks & regards
rohit
Kurt_Bremser
Super User

But your previous post showed two strings in the first observation:


@rohitkrishna wrote:
Ya novinosrin,
i want the rec into vertical
like
R M********N
T**B
like above one after another
Thanks & regards
rohit

 

Kurt_Bremser
Super User

So you have three strings in one input line, and you want the third string to go into a new observation?


@rohitkrishna wrote:
Hi novinosrin
Thanks for the response
please find below mention data
{
R M********N T**B
D N******E T**B
L H**********N T**B
R S***********N T**B
K *******L T**B
Thanks & regards
rohit

 

rohitkrishna
Calcite | Level 5
Hi KurtBremser,
ya i have three fields in one line and i want it to be one after the other like Horizontal to vertical
Thanks & regards
Rohit
rohitkrishna
Calcite | Level 5
Hi
try to provide some solution for the above issue
Thanks & regards
Rohit
Kurt_Bremser
Super User

@rohitkrishna wrote:
Hi
try to provide some solution for the above issue
Thanks & regards
Rohit

Since your rule does not match your expected output, I can't do that.

rohitkrishna
Calcite | Level 5
Hi KurtBremser,
ya sorry for the trouble i will explain in a simpley way
please find below the code
{
data _null_;
infile insfdt missover;
put @1 name $char26.
@28 sex $char1.
@30 surname @char28. @;
return;
put @1 name $char26.
@28 sex $char1.
@30 surname @char28.;
run;
and the output looks
("carline f karei") that is the output in a single line
but my req is
{ carline
f
karei}
like above one
Thanks & regards
Rohit





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
  • 17 replies
  • 2830 views
  • 0 likes
  • 5 in conversation