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 8230367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:06:31+00:00 2026-06-07T17:06:31+00:00

I have a dataset that looks something like this: IDnum State Product Consumption 123

  • 0

I have a dataset that looks something like this:

IDnum    State    Product    Consumption
123      MI       A          30
123      MI       B          20
123      MI       C          45
456      NJ       A          15
456      NJ       D          10
789      MI       B          60
...      ...      ...        ...

And i would like to create a new dataset, where i have one row for each IDnum, and a new dummy variable for each different product (in my real dataset i have close to 1000 products), along with it’s associated consumption. It would look like something in these lines

IDnum   State   Prod.A   Cons.A   Prod.B   Cons.B   Prod.C   Cons.C   Prod.D   Cons.D
123     MI      yes      30       yes      20       yes      45       no       -
456     NJ      yes      15       no       -        no       -        yes      10
789     MI      no       -        yes      60       no       -        no       -
...     ...     ...      ...      ...      ...      ...      ...      ...      ...

Some variables like “State” doesn’t change within the same IDnum, but each row in the original bank are equivalent to one purchase, hence the change in the “product” and “consumption” variables for the same IDnum. I would like that my new dataset showed all the consumption habits of each costumer in one single row, but so far i have failed.

Any help would be greatly apreciated.

  • 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-07T17:06:34+00:00Added an answer on June 7, 2026 at 5:06 pm

    Without yes/no variables, it’s really easy:

    data input;
    length State $2 Product $1;
    input IDnum    State    Product    Consumption;
    cards;
    123      MI       A          30
    123      MI       B          20
    123      MI       C          45
    456      NJ       A          15
    456      NJ       D          10
    789      MI       B          60
    ;
    run;
    
    proc transpose data=input out=output(drop=_NAME_) prefix=Cons_;
      var Consumption;
      id Product;
      by IDnum State;
    run;
    

    Adding the yes/no fields:

        proc sql;/* from column names or alternatively 
                    create it from source data directly if not taking too long */
        create table work.products as
            select scan(name, 2, '_') as product length=1
            from dictionary.columns 
                        where libname='WORK' and memname='OUTPUT' 
                          and  upcase(name) like 'CONS_%';
        quit;
    
        filename vars temp;/* write a temp file containing variable definitions
                           in desired order */
        data _null_;
            set  work.products end=last;
            file vars;
                        length str $40;
            if _N_ = 1 then put 'LENGTH ';
            str = catt('Prod_', product, ' $3');
            put str;
            str = catt('Cons_', product, ' 8');
            put str;
            if last then put ';';
        run;
    
        options source2;
        data output2;
            length IdNum 8 State $2;
            %include vars;
            set output;
            array prod{*} Prod_:;
            array cons{*} Cons_:;
            drop i;
            do i=1 to dim(prod);
                if coalesce(cons(i), 0) ne 0 then prod(i)='yes';
                else prod(i)='no';
            end;
        run;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset in Reporting Services that looks something like this: ID |
I have an ajax request that looks like this, $(#frmProducts).submit(function(){ var dataSet = $(#frmProducts).serialize();
I have a data set that looks something like this: Gender | Age |
I have a data set that looks something like this: Gender | Age |
I have a (dense) dataset that consist of 5 groups, so my data.frame looks
I've created an ajax driven flot line chart that I would like to have
I have a data set that looks like the below (the input). IR# CR#
I have a dataset that i am trying to set the default value as
I have a dataset that returns questions and answers from the database, each answer
I have a large dataset that load in with a fill method on page

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.