BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jackice
Calcite | Level 5

Hi everyone, is there an easy programmation way of 1) creating a new variable "NUTID", 2) then adding as many new lines to dataset as a previous variable "NUT" - how to go from left table in this attached excel to right end side table - PLEASE? 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Here is one way to had a variable that takes on values of 1 to n of an existing variable.

 

data have;
   input a b;
datalines;
1 2
3 4
5 3
;
run;

data want;
   set have;
   do nutid = 1 to a;
      output;
   end;
run;
   

The key is the output. This will create a new record each time that the Output statement executes. All other varaibles in the data set will duplicate.

 

View solution in original post

3 REPLIES 3
Reeza
Super User

1. Create a list of the values needed in each column

2. Create the 'big dataset' which is empty using cross join in SQL

3. Merge in initial table to fill the values.

 

 

ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Here is one way to had a variable that takes on values of 1 to n of an existing variable.

 

data have;
   input a b;
datalines;
1 2
3 4
5 3
;
run;

data want;
   set have;
   do nutid = 1 to a;
      output;
   end;
run;
   

The key is the output. This will create a new record each time that the Output statement executes. All other varaibles in the data set will duplicate.

 

jackice
Calcite | Level 5

Thank you kindly speedy useful user ;-0) Exactly what I wanted - TKS and ill look at how to post with no excel file next time ;-0) 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1083 views
  • 0 likes
  • 3 in conversation