BookmarkSubscribeRSS Feed
Meteorite | Level 14


I have a data set with wide structure: for each month there is information of multiple variables .

Some of the variables are numeric and some are char.

For some char variables there is user defined format .

I want to convert the structure from wide to Long .

The wanted structure (Long ) will show me information of multiple variables for each month.

After the transpose I see strange values

Why did it happen?

Is it because  there is mix of numeric and char vars before proc transpose?

Should I convert the numeric to char before do trapspose?




Meteorite | Level 14

How about doing something like this:

data have;
input month a b $ c d $;
1 11 A 100 ABC
2 22 B 200 DEF
3 33 C 300 GHI
4 44 D 400 JKL
proc print;

data want (compress=char);
  set have;

  array NN[*] a-Numeric-d;
  array CC[*] a-Character-d;

  length varName varFmnt $ 32 valNum 8 valChar $ 200;

  call missing(valNum,valChar);
  do _N_=1 to dim(NN);

  call missing(valNum,valChar);
  do _N_=1 to dim(CC);

  keep month varName varFmnt valNum valChar;
  format varName varFmnt valNum valChar;
proc print;


Numeric values stay in numeric, character in character, and format value is stored.



Polish SAS Users Group: and

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation

Meteorite | Level 14
I would like to know please why did it happen that after proc transpose (wide to long) there are such values?
By the way,these values are not null values. May anyone tell what is this symbol of this values?
Super User

@Ronein wrote:



After the transpose I see strange values

Why did it happen?





Which ones are "strange values" we do not have your source data set. We do not know anything about the data or the meaning of any values.

You don't even show the code you used.

Transpose does not work well with Numeric and Character variables as VAR variables.


Whats wrong with a report? You keep trying to create obnoxious data sets. If the purpose is "show me information of multiple variables for each month" sounds like a report is more likely useful than a data set. Plus the picture you show does not appear to have any "Month" information involved.


Getting multiple Col for any given "_name_" value means that if you used any sort of by to group the data then the by variable(s) have multiple identical values and your approach to "long" may not have been prepared correctly.


Show starting data in a usable form.

Diamond | Level 26

Agreeing with @ballardw 


You put yourself in difficult situations by continually trying to work with data sets that are not in a format that SAS was designed to handle. In this case, you seem to have a different variable in each row, and values for that variable going across the rows. This is the EXACT OPPOSITE of what it is supposed to be for easy SAS coding, in which variables are columns and the values of the variable are going down the columns. You need to learn to recognize this and avoid it like the plague.


Do not create data sets like this, or like the one with the exact same problem in an earlier thread. Recognize that this a bad habit pattern we see from you, and begin trying to correct this bad habit pattern.

Paige Miller



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4 in conversation