Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:19:55+00:00 2026-06-13T11:19:55+00:00

I inherited a horribly-designed table where data is stored like this: Period | Identifier

  • 0

I inherited a horribly-designed table where data is stored like this:

Period |  Identifier |   Value
----------------------------------
1      | AB1         | some number
1      | AB2         | some number
1      | AB3         | some number
1      | AB4         | some number
1      | AB5         | some number
1      | A1          | some number
1      | A2          | some number
1      | A3          | some number
1      | A4          | some number
1      | A5          | some number
2      | AB1         | some number
2      | AB2         | some number
2      | AB3         | some number
2      | AB4         | some number
2      | AB5         | some number
2      | A1          | some number
2      | A2          | some number
2      | A3          | some number
2      | A4          | some number
2      | A5          | some number

I’m trying to use SELECT statements that will get data into this format:

Row # | First value | Second value
1     | A1's number | AB1's number     // The next 5 rows are data from period 1
2     | A2's number | AB2's number
3     | A3's number | AB3's number
4     | A4's number | AB4's number
5     | A5's number | AB5's number
6     | A1's number | AB1's number     // These 5 rows are from period 2
7     | A2's number | AB2's number
8     | A3's number | AB3's number
9     | A4's number | AB4's number
10    | A5's number | AB5's number

AB% and A% are two separate ID’s of that format, which mildly frustrates WHERE LIKE ... clauses, I think. I’m not entirely sure the data can be forced into the desired format, but my supervisor asked me to look into it.

My initial attempt, for which I don’t know the SQL code for, would be to look at the row number itself and work with, but as I said, I’m unsure how to progress down that route.

Right now, the data is in SQL Server, but it will be accessed from SAS using proc sql. I think those standards conform to SQL Server for the most part, even though DECLARE isn’t supported.

And no, I don’t know whose idea it was to store the data in this fashion…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:19:56+00:00Added an answer on June 13, 2026 at 11:19 am

    If you’re using SAS, then I’d just use PROC TRANSPOSE. Get the data to include a label variable, which determines which variable the data will be moved to:

    data datatable;
    infile datalines dlm='|';
    input
    Period Identifier $ Value $;
    datalines;
    1      | AB1         | some number
    1      | AB2         | some number
    1      | AB3         | some number
    1      | AB4         | some number
    1      | AB5         | some number
    1      | A1          | some number
    1      | A2          | some number
    1      | A3          | some number
    1      | A4          | some number
    1      | A5          | some number
    2      | AB1         | some number
    2      | AB2         | some number
    2      | AB3         | some number
    2      | AB4         | some number
    2      | AB5         | some number
    2      | A1          | some number
    2      | A2          | some number
    2      | A3          | some number
    2      | A4          | some number
    2      | A5          | some number
    ;;;
    run;
    
    data have;
    set datatable;
    idlabel = compress(identifier, ,'d');
    byval = compress(identifier,,'kd');
    run;
    
    proc sort data=have;
    by period byval;
    run;
    proc transpose data=have out=want;
    by period byval;
    id idlabel;
    var value;
    run;
    

    If for some reason you HAVE to do it in SQL, you are best off doing it as a join to itself. You want to join the row where period=1 and compress(identifier,,’kd’)=1 for both AB and A, so you can do that:

    proc sql;
      create table want as 
        select A.period, AB.value as AB, A.value as A
        from (select * from have where compress(identifier,,'d')='AB') AB, 
             (select * from have where compress(identifier,,'d')='A') A
        where AB.period=A.period
        and compress(AB.identifier,,'kd') = compress(A.identifier,,'kd');
    quit;
    

    But the PROC TRANSPOSE option is likely to be more efficient than the self join, I’d think (and more flexible, if your data isn’t quite as pretty as you show).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i inherited this code from some-one and this only returns the first row it
I inherited several projects Javas in my new job, but I'm having some problems
I inherited a system that stores default values for some fields in some tables
I inherited a bugzilla-like page that allows users to look at the bug list.
Ive inherited some code which started out as an Android project but really is
I inherited my scene from QGraphicsScene. I add many items(QGraphicslineItem, QGraphicsItem, QGraphicsTextItem) on this
I have an index page for listing products. From this page I would like
I've inherited a clunky and horribly un-documented site from a bad developer and am
I inherited a coldfusion8 site, which is using some search functionality. I'm trying to
I inherited a WCF project containing some badly constructed routes (which work) that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.